Javascript 使用@

Javascript 使用@,javascript,json,Javascript,Json,在这个问题的末尾是从ebay api调用返回的标准JSON 我在解析大部分内容时没有问题,例如,为了获得标题、剩余时间等,我正在使用: var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || []; for (var i = 0; i < items.length; ++i) { var item = items[i]; var title = item.title; var

在这个问题的末尾是从ebay api调用返回的标准JSON

我在解析大部分内容时没有问题,例如,为了获得标题、剩余时间等,我正在使用:

var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];

for (var i = 0; i < items.length; ++i) {
    var item = items[i];
    var title = item.title;
    var timeLeft= item.sellingStatus[0].timeLeft;
}
但控制台告诉我箭头指向@符号的非法字符-正确的解析方法是什么

{
   "findItemsByKeywordsResponse":[
      {
         "ack":[
            "Success"
         ],
         "version":[
            "1.12.0"
         ],
         "timestamp":[
            "2014-03-26T18:29:40.583Z"
         ],
         "searchResult":[
            {
               "@count":"100",
               "item":[
                  {
                     "itemId":[
                        "151258132867"
                     ],
                     "title":[
                        "Apple iPhone 4 - clean esn - Black (Verizon) Smartphone"
                     ],
                     "globalId":[
                        "EBAY-US"
                     ],
                     "primaryCategory":[
                        {
                           "categoryId":[
                              "9355"
                           ],
                           "categoryName":[
                              "Cell Phones & Smartphones"
                           ]
                        }
                     ],
                     "galleryURL":[
                        "http:\/\/thumbs4.ebaystatic.com\/m\/mGwHzpyvkph9-nU12sCspxw\/140.jpg"
                     ],
                     "viewItemURL":[
                        "http:\/\/www.ebay.com\/itm\/Apple-iPhone-4-clean-esn-Black-Verizon-Smartphone-\/151258132867?pt=Cell_Phones"
                     ],
                     "productId":[
                        {
                           "@type":"ReferenceID",
                           "__value__":"101787954"
                        }
                     ],
                     "paymentMethod":[
                        "PayPal"
                     ],
                     "autoPay":[
                        "false"
                     ],
                     "postalCode":[
                        "93905"
                     ],
                     "location":[
                        "Salinas,CA,USA"
                     ],
                     "country":[
                        "US"
                     ],
                     "shippingInfo":[
                        {
                           "shippingServiceCost":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"0.0"
                              }
                           ],
                           "shippingType":[
                              "Free"
                           ],
                           "shipToLocations":[
                              "US"
                           ],
                           "expeditedShipping":[
                              "true"
                           ],
                           "oneDayShippingAvailable":[
                              "false"
                           ],
                           "handlingTime":[
                              "2"
                           ]
                        }
                     ],
                     "sellingStatus":[
                        {
                           "currentPrice":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"96.0"
                              }
                           ],
                           "convertedCurrentPrice":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"96.0"
                              }
                           ],
                           "bidCount":[
                              "17"
                           ],
                           "sellingState":[
                              "Active"
                           ],
                           "timeLeft":[
                              "P0DT0H0M11S"
                           ]
                        }
                     ],
                     "listingInfo":[
                        {
                           "bestOfferEnabled":[
                              "false"
                           ],
                           "buyItNowAvailable":[
                              "false"
                           ],
                           "startTime":[
                              "2014-03-19T18:29:51.000Z"
                           ],
                           "endTime":[
                              "2014-03-26T18:29:51.000Z"
                           ],
                           "listingType":[
                              "Auction"
                           ],
                           "gift":[
                              "false"
                           ]
                        }
                     ],
                     "returnsAccepted":[
                        "false"
                     ],
                     "condition":[
                        {
                           "conditionId":[
                              "3000"
                           ],
                           "conditionDisplayName":[
                              "Used"
                           ]
                        }
                     ],
                     "isMultiVariationListing":[
                        "false"
                     ],
                     "topRatedListing":[
                        "false"
                     ]
                  },
                  {
                     "itemId":[
                        "360810145746"
                     ],
                     "title":[
                        "U Apple iPhone 3GS - 8GB - Black (FACTORY UNLOCKED) Smartphone (C)"
                     ],
                     "globalId":[
                        "EBAY-US"
                     ],
                     "subtitle":[
                        "****USA SELLER*****FAST SHIPPING*****TOP SELLER****"
                     ],
                     "primaryCategory":[
                        {
                           "categoryId":[
                              "9355"
                           ],
                           "categoryName":[
                              "Cell Phones & Smartphones"
                           ]
                        }
                     ],
                     "galleryURL":[
                        "http:\/\/thumbs3.ebaystatic.com\/m\/mQGXy5hucEtqk6inUKFu67g\/140.jpg"
                     ],
                     "viewItemURL":[
                        "http:\/\/www.ebay.com\/itm\/U-Apple-iPhone-3GS-8GB-Black-FACTORY-UNLOCKED-Smartphone-C-\/360810145746?pt=Cell_Phones"
                     ],
                     "productId":[
                        {
                           "@type":"ReferenceID",
                           "__value__":"99984545"
                        }
                     ],
                     "paymentMethod":[
                        "PayPal"
                     ],
                     "autoPay":[
                        "true"
                     ],
                     "postalCode":[
                        "10001"
                     ],
                     "location":[
                        "New York,NY,USA"
                     ],
                     "country":[
                        "US"
                     ],
                     "shippingInfo":[
                        {
                           "shippingServiceCost":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"0.0"
                              }
                           ],
                           "shippingType":[
                              "Free"
                           ],
                           "shipToLocations":[
                              "US",
                              "CA",
                              "GB",
                              "AU",
                              "FR",
                              "HK",
                              "MT",
                              "IE",
                              "IL",
                              "NZ",
                              "PH",
                              "SG"
                           ],
                           "expeditedShipping":[
                              "true"
                           ],
                           "oneDayShippingAvailable":[
                              "false"
                           ],
                           "handlingTime":[
                              "1"
                           ]
                        }
                     ],
                     "sellingStatus":[
                        {
                           "currentPrice":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"84.95"
                              }
                           ],
                           "convertedCurrentPrice":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"84.95"
                              }
                           ],
                           "sellingState":[
                              "Active"
                           ],
                           "timeLeft":[
                              "P12DT0H9M11S"
                           ]
                        }
                     ],
                     "listingInfo":[
                        {
                           "bestOfferEnabled":[
                              "false"
                           ],
                           "buyItNowAvailable":[
                              "false"
                           ],
                           "startTime":[
                              "2013-12-08T18:33:51.000Z"
                           ],
                           "endTime":[
                              "2014-04-07T18:38:51.000Z"
                           ],
                           "listingType":[
                              "StoreInventory"
                           ],
                           "gift":[
                              "false"
                           ]
                        }
                     ],
                     "returnsAccepted":[
                        "true"
                     ],
                     "condition":[
                        {
                           "conditionId":[
                              "3000"
                           ],
                           "conditionDisplayName":[
                              "Used"
                           ]
                        }
                     ],
                     "isMultiVariationListing":[
                        "false"
                     ],
                     "discountPriceInfo":[
                        {
                           "originalRetailPrice":[
                              {
                                 "@currencyId":"USD",
                                 "__value__":"449.0"
                              }
                           ],
                           "pricingTreatment":[
                              "STP"
                           ],
                           "soldOnEbay":[
                              "false"
                           ],
                           "soldOffEbay":[
                              "false"
                           ]
                        }
                     ],
                     "topRatedListing":[
                        "true"
                     ]
                  } 

您需要使用带括号表示法的字符串访问该属性

var currencyID= item.sellingStatus[0].currentPrice[0]["@currencyId"];
只要属性不是以alpha、\uu$字符开头,就需要执行此操作

get=object.property

object.property=set

属性必须是有效的JavaScript标识符,即字母数字字符序列,还包括下划线(“389;”)和美元符号($”),不能以数字开头。例如,object.$1有效,而object.1无效


您需要使用带括号表示法的字符串访问该属性

var currencyID= item.sellingStatus[0].currentPrice[0]["@currencyId"];
只要属性不是以alpha、\uu$字符开头,就需要执行此操作

get=object.property

object.property=set

属性必须是有效的JavaScript标识符,即字母数字字符序列,还包括下划线(“389;”)和美元符号($”),不能以数字开头。例如,object.$1有效,而object.1无效


您可以使用
var currencyID=item.sellingStatus[0].currentPrice[0]['@currencyID']
您可以使用
var currencyID=item.sellingStatus[0].currentPrice[0]['@currencyID']非常感谢,当我可以的时候会接受。。。有没有一个原因,他们会用这种方式来格式化它,而不是一个普通的字符串,比如currencyId?没有,我想不出他们这样做的原因,可能是他们使用的一些内部结构。他们api的开发人员可能是唯一知道的人。非常感谢,当我能。。。有没有一个原因,他们会用这种方式来格式化它,而不是一个普通的字符串,比如currencyId?没有,我想不出他们这样做的原因,可能是他们使用的一些内部结构。他们api的开发人员可能是唯一知道的人。