【发布时间】:2018-05-12 09:23:51
【问题描述】:
给定这个嵌套的 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_"];
作为记录,我试图访问响应中的 convertCurrentPrice 值,而不是我最初声明的 currentPrice 值。仍然没有运气。也一直在寻找教程,但到目前为止还没有找到任何从请求回调深入到索引嵌套 jsonp 的内容。任何人都知道任何涵盖此的教程?再次感谢。
【问题讨论】:
-
currentPrice是数组...试试item.sellingStatus[0]["currentPrice"][0]["_value_"];
标签: javascript json indexing