所以我在Nodejs中创建了这段代码:
var stemidLength= JSON.memberList.members[0].length;
for (stemidIndex = 0; stemidIndex < stemidLength; stemidIndex++) {
var steamID64Length= JSON.memberList.members[steamidIndex].steamID64.length;
for (steamid64Index = 0; steamid64Index < steamid64Length; steamid64Index++) {
steam.addFriend(steamID64[i]);
}
}
我正在尝试从xml页面中提取steamid64s:http://steamcommunity.com/groups/Valve/memberslistxml/?xml=1.
我已经将xml页面转换为JSON数组.
我的代码有什么问题?得到错误:
cannot read property ‘members’ of undefined.
编辑:JSON提取的数组:http://pastebin.com/FECXEKMD
谢谢.
最佳答案 JSON对象是一个内置对象,用于解析JSON并将字符串转换为JSON.它没有memberList属性.
我将把XML到JSON转换的结果称为steamUsers.
可以在steamUsers.memberList.members [0] .steamID64中找到ID.您可以使用以下代码添加ID:
xmlToJson(urlxml, function(err, data) {
if (err) {
return console.err(err);
}
var steamUsers = data;
steamUsers.memberList.members[0].steamID64.forEach(function(memberID) {
steam.addFriend(memberID);
console.log(memberID);
});
});