我正在尝试从JSON对象访问Casino Games及其属性列表,以便让它们显示在网站上。这是我到目前为止的地方。
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包含带有游戏数据的对象。
另见:http://pasteboard.co/kXb1Voq.png 相关小提琴:http://jsfiddle.net/emporio/vz24dtm8/5/
这个问题很独特,因为它需要访问唯一的属性。答案还提供了多种检索数据的方法。
答案 0 :(得分:1)
JS
var Games;
var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", function (data) {
Games = data.d;
}).done(function () {
document.getElementById('choice').innerHTML=ProcessProgressiveGames(Games);
});
function ProcessProgressiveGames(progressiveGames) {
return progressiveGames.Games[0].GameName;
}
答案 1 :(得分:0)
$.getJSON
函数返回promise,处理从该地址返回的数据的正确方法是设置第二个参数 - 处理数据的函数
$.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;
}
答案 2 :(得分:0)
您可以尝试这样
var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);
http://jsfiddle.net/vz24dtm8/8/
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;
}
答案 3 :(得分:0)
[DEFAULT]
DefaultApplVerID=FIX.5.0SP2
ConnectionType=initiator
ReconnectInterval=60
FileStorePath=store
FileLogPath=*store
HttpAcceptPort=8080
HeartBtInt=30
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=Y
DataDictionary=quickfix/FIX50SP2.xml
TransportDataDictionary=quickfix/FIXT11.xml
ValidateUserDefinedFields=N
ResetOnLogout=Y
ResetOnLogon=Y
MySQLStoreDatabase=quickfix
MySQLStoreUser=user
MySQLStorePassword=password
MySQLStoreHost=ip address
MySQLLogDatabase=quickfix
MySQLLogUser=user
MySQLLogPassword=password
MySQLLogHost=0.0.0.0
[SESSION]
BeginString=FIXT.1.1
SenderCompID=senderid
TargetCompID=targetid
SocketConnectPort=port
SocketConnectHost=host