Javascript 从JSON获取游戏及其属性的列表

Javascript 从JSON获取游戏及其属性的列表,javascript,json,Javascript,Json,我试图从JSON对象访问赌场游戏及其属性的列表,以便在网站上显示它们。到目前为止,我就在这里 var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames); console.log(x); function ProcessProgressiveGames(progressiveGames)

我试图从JSON对象访问赌场游戏及其属性的列表,以便在网站上显示它们。到目前为止,我就在这里

var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);
console.log(x);

function ProcessProgressiveGames(progressiveGames) {
     console.log(progressiveGames.d.Games[0].GameName);
}
最好的方法是什么。如果您检查控制台,您将看到var x包含带有游戏数据的对象

另见: 相关小提琴:

这个问题是唯一的,因为它需要访问唯一的属性。答案还提供了多种检索数据的方法。

函数返回promise,处理从该地址返回的数据的正确方法是设置第二个参数-function来处理数据

$.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);

function ProcessProgressiveGames(progressiveGames) {
    // Note that progressiveGames has a property 'd' containing the data we're interested in.
    console.log(progressiveGames);
    document.getElementById('choice').innerHTML = ProcessProgressiveGames(x);
     return progressiveGames.d.Games[0].GameName;
}
JS

你可以这样试试

var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);

让你的问题更一般,你甚至不需要提问。建议的可能重复:请与函数和变量名一起使用。ProcessProgressiveGames看起来像一个对象定义。而是使用processGamesOnSuccess之类的名称。更具描述性。JavaScript不是C。好的,谢谢!我不明白为什么这个问题太宽泛了。我已经提供了JSON对象的链接。我只需要提取数据,我得到了帮助。我的问题解决了。
var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);
function ProcessProgressiveGames(data) {
    // Note that progressiveGames has a property 'd' containing the data we're interested in.

     return document.getElementById('choice').innerHTML=data.d.Games[0].GameName;

}
    <pre>Use callback function to get the json value and pass the parameter in callback function</pre>