我的 javascript 知识非常有限.. 我很感激任何建议.. 我查看了以前的 JSON 问题和答案,但没有看到任何与此类似的内容。
我正在使用 jQuery。我有以下格式的 JSON 服务器响应:
{
"aNumBids_1": "4",
"aHighBid_1": "100.00",
"aBidAmount_1": "110.00",
"aBidEnd_1": "09/27/2013 17:00",
"aNumBids_2": "42",
"aHighBid_2": "1,210.00",
"aBidAmount_2": "1,260.00",
"aBidEnd_2": "09/27/2013 17:01",
"aNumBids_3": "12",
"aHighBid_3": "1,100.00",
"aBidAmount_3": "1,150.00",
"aBidEnd_3": "09/27/2013 17:02",
"aNumBids_4": "26",
"aHighBid_4": "1,460.00",
"aBidAmount_4": "1,510.00",
"aBidEnd_4": "09/27/2013 17:03",
"aNumBids_5": "32",
"aHighBid_5": "1,210.00",
"aBidAmount_5": "1,260.00",
"aBidEnd_5": "09/27/2013 17:04"
}
每对的第一个元素是页面上的元素名称 ( name='aBidAmount_5'
)。每对的第二个元素是要放入该元素的内容。
我该如何遍历这个 json 响应?
我已经做到了这一点:
AJAX.getPrice = function(){
var request = $.ajax({
url: serverScript,
data: JSON.stringify(aItems) ,
dataType: "json"
});
request.done(function() {
// update the element value
/* i'm lost here */
});
request.fail(function(jqXHR, textStatus) {
// If console is available output the error to console log
if (typeof console == "object") {
console.log( "Request failed: " + textStatus +data );
}
});
}