给定此嵌套的JSON响应
{
"findCompletedItemsResponse":[
{
"ack":[
"Success"
],
"version":[
"1.13.0"
],
"timestamp":[
"2017-11-28T19:23:07.161Z"
],
"searchResult":[
{
"@count":"2",
"item":[
{
"itemId":[
"222664349999"
],
"title":[
"Nikon IK467-156 Remote Terminal Cover 10-Pin for D2X, D2Xs, D2H, F5, F90, F100"
],
"globalId":[
"EBAY-ENCA"
],
"galleryURL":[
"http://thumbs4.ebaystatic.com/m/mvCz__whMmEvIJIvq0Li1qQ/140.jpg"
],
"viewItemURL":[
"http://www.ebay.com/itm/Nikon-IK467-156-Remote-Terminal-Cover-10-Pin-D2X-D2Xs-D2H-F5-F90-F100-/222664349999"
],
"paymentMethod":[
"PayPal"
],
"autoPay":[
"false"
],
"postalCode":[
"B2R1C3"
],
"location":[
"Canada"
],
"country":[
"CA"
],
"sellingStatus":[
{
"currentPrice":[
{
"@currencyId":"CAD",
"__value__":"5.0"
}
],
value 的索引是什么?我目前正在通过此代码访问上方的所有内容:
var items = result.findCompletedItemsResponse[0].searchResult[0].item || [];
var html = [];
html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var title = item.title;
var pic = item["galleryURL"];
var viewitem = item.viewItemURL;
var sellPrice = item.sellingStatus[0]["currentPrice"]["_value_"];
我试图将sellprice设置为JSON响应中 value 条目的值,但似乎无法找出适当的语法来访问索引。
感谢您的回复。不幸的是,该方法无效。仍在试图解决这个问题。我也尝试了以下代码,但我遇到了同样的错误:
var sellPrice=result.findCompletedItemsResponse[0].searchResult[0].item[0].sellingStatus[0].convertedCurrentPrice || [];
for (var j = 0; j < sellPrice.length; ++j) {
var convertedCurrentPrice = sellPrice[j];
var soldPrice = convertedCurrentPrice["_value_"];
对于记录,我试图在响应中访问convertedCurrentPrice值,而不是我最初说明的当前值。仍然没有运气。也在四处寻找教程,但到目前为止,还没有发现任何深入索引中的JSONP的内容。有人知道有什么教程涵盖了这一点吗?再次感谢。
var sellPrice = item.sellingStatus[0]["currentPrice"][0]["_value_"];
CurrentPrice是一个具有单个货币块的数组