大家好我在node.js写了一些代码,并在Json格式的文本文件中有一些数据,我想把它们放在div中,但我没有任何输出,我的代码在这里有错误的部分:& #34; var curServer = serverData [server];"以及如何从数据中获取IP和端口,我也不知道如何解决这个问题 谁能告诉我如何解决?!
{
"servers":{
"192.168.1.2:28961":{
"hostname":"PlusMaster-Test",
"mod":"",
"gametype":"DOM",
"clients":"1",
"sv_maxclients":"18",
"mapname":"Crash",
"players":[
{
"name":"MaximuM",
"ping":"999",
"score":"0"
}
]
},
"192.168.1.3:28962":{
"hostname":"PlusMaster-Test2",
"mod":"",
"gametype":"DOM",
"clients":"1",
"maxclients":"18",
"mapname":"Crash",
"players":[
{
"name":"MaximuM",
"ping":"999",
"score":"0"
}
]
}
},
"last_updated":"2016-03-03T10:07:12.929Z"
}
resopn2.txt:
quickfix.fix44.NewOrderList fixMessage = new quickfix.fix44.NewOrderList (
.... // check constructor for what parameters to pass
);
// ...
quickfix.fix44.NewOrderList.NoOrders noOrders = new quickfix.fix44.NewOrderList.NoOrders();
// ...
fixMessage.addGroup( noOrders );
答案 0 :(得分:1)
您只需进行一些更改即可。它们如下:
resopn2.txt:
{
"servers":[
{
"ip_address" : "192.168.1.2",
"port":"28961",
"hostname":"PlusMaster-Test",
"mod":"",
"gametype":"DOM",
"clients":"1",
"sv_maxclients":"18",
"mapname":"Crash",
"players":[
{
"name":"MaximuM",
"ping":"999",
"score":"0"
}
]
},
{
"ip_address" : "192.168.1.3",
"port":"28962",
"hostname":"PlusMaster-Test2",
"mod":"",
"gametype":"DOM",
"clients":"1",
"maxclients":"18",
"mapname":"Crash",
"players":[
{
"name":"MaximuM",
"ping":"999",
"score":"0"
}
]
}
],
"last_updated":"2016-03-03T10:07:12.929Z"
}
功能更改:populateServers
function populateServers(serverData) {
var serverData = JSON.stringify(test);
serverData = JSON.parse(serverData);
for (server=0; server < serverData.servers.length; server++) {
var curServer = JSON.stringify(serverData.servers[server]);
curServer = JSON.parse(curServer);
$('#serverBasket').append(
'<a href="pmiw4m://' + ipv4FromNumber(curServer.address) + ':' + curServer.port + '"> \
<div class="serverHolder"> \
<div class="serverPrimary"> \
<span class="hostname">'+ curServer.hostname + '</span><br /> \
<span class="map">' + curServer.mapname + '</span><br /> \
<span class="gametype">' + curServer.gametype + '</span><br /> \
<span class="players">'+ curServer.clients + '/' + curServer.sv_maxclients + '</span> \
</div> \
</div> \
</a>' );
}
}
希望有所帮助