您好我正在开发列出所有平台游戏的网络应用程序。为此,我也有api。 Api格式是这样的:
{
"title":"Doom 3: BFG Edition",
"platform":"Xbox 360",
"score":7.6,
"genre":"RPG",
"editors_choice":"N"
}
假设我只从api解析pc(平台)结果。我如何从jquery中的api解析它?
答案 0 :(得分:1)
如果你试图解析json响应,那么你可以像下面这样做
x = {
"title":"Doom 3: BFG Edition",
"platform":"PC",
"score":7.6,
"genre":"RPG",
"editors_choice":"N"
}
console.log("Title : " + x.title);
console.log("platform : " + x.platform);
console.log("score : " + x.score);
console.log("genre : " + x.genre);
console.log("editors choice : " + x.editors_choice);
if(x.platform == "PC"){
alert("game is pc platform !");
}
var data = [
{"Game": "Gears Of War", "PlatForm": "PC"},
{"Game": "NFS Most Wanted", "PlatForm": "X-Box"},
{"Game": "xyz", "PlatForm": "PS3"}
];
$.each(data, function(i, item) {
alert(data[i].Game + data[i].PlatForm);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
答案 1 :(得分:0)
var items= {
"title":"Doom 3: BFG Edition",
"platform":"Xbox 360",
"score":7.6,
"genre":"RPG",
"editors_choice":"N"
}
console.log(items.platform);