大家好我是json的新手,我正试图获得黄金第3级内容的价格 - > MyFeed-> XAUCAD-> bid H从php代理获取此供稿可以有人帮忙如何获得金价
$(document).ready(function () {
$.getJSON("http://feed.php",
function (data) {
alert(data.gold);
});
});
JSON
{
"headers": {
"Cache-Control": "private",
"Content-Type": "application/json; charset=utf-8",
"Server": "Microsoft-IIS/7.0",
"X-AspNet-Version": "4.0.30319",
"X-Powered-By": "ASP.NET",
"X-Served-By": "",
"Date": "Wed, 22 Jan 2014 06:35:06 GMT",
"Content-Length": "200"
},
"status": {},
"contents": {
"MyFeed": {
"@Provider": "FastMarkets",
"XAUCAD": {
"@name": "Gold Canadian $",
"bid_time": "20140122063506",
"bid": "1360.44"
},
"XAGCAD": {
"@name": "Silver Canadian $",
"bid_time": "20140122063507",
"bid": "21.76"
}
}
}
}
答案 0 :(得分:2)
console.log(data.contents.MyFeed.XAUCAD.bid);
答案 1 :(得分:1)
我已经考虑过你提到过的数据= JSON文件
$(document).ready(function () {
$.getJSON("http://feed.php",
function (data) {
//This should open alert dialog containing gold bid
alert(data.contents.MyFeed.XAUCAD.bid);
});
});
答案 2 :(得分:0)
你可以这样做
var a ={
"headers": {
"Cache-Control": "private",
"Content-Type": "application/json; charset=utf-8",
"Server": "Microsoft-IIS/7.0",
"X-AspNet-Version": "4.0.30319",
"X-Powered-By": "ASP.NET",
"X-Served-By": "",
"Date": "Wed, 22 Jan 2014 06:35:06 GMT",
"Content-Length": "200"
},
"status": {
},
"contents": {
"MyFeed": {
"@Provider": "FastMarkets",
"XAUCAD": {
"name": "Gold Canadian $",
"bid_time": "20140122063506",
"bid": "1360.44"
},
"XAGCAD": {
"name": "Silver Canadian $",
"bid_time": "20140122063507",
"bid": "21.76"
}
}
}
}
$(document).ready(function(){
alert(a.contents.MyFeed.XAUCAD.bid);
});