给出这个嵌套的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"
}
],
值的索引是什么?我目前正在通过以下代码访问以上销售状态:
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值,而不是我最初声明的currentPrice值。仍然没有运气。一直在寻找教程,但到目前为止还没有找到任何深入到请求回调的索引嵌套jsonp。有人知道任何涵盖这个的教程吗?再次感谢。
答案 0 :(得分:0)
var sellPrice = item.sellingStatus[0]["currentPrice"][0]["_value_"];
CurrentPrice是一个包含单个货币区块的数组