我目前正在尝试从JSON对象中提取数据。解析后并尝试访问其中的数据。我能够成功获取JSON对象的数值和布尔值,但字符串对象只返回一个空字符串。有什么我想念的吗?我假设代码是正确的,因为我得到其他值就好了。如果需要帮助,我可以发布代码。
提前致谢。
编辑:
//getting the object layer of the TILED map in a for loop
for (var layeridX = 0; layeridX < TILEDATA_CACHE[index].layers.length; layeridX++) {
if (TILEDATA_CACHE[index].layers[layeridX].type !== "objectgroup") continue;
var tileObjects = TILEDATA_CACHE[index].layers[layeridX].objects;
var obj = {
"name": "",
"width": 0,
"x": 0,
"y": 0
};
...other irrelevant code here...
obj.name = tileObjects[x].name; //PROBLEM, it gives a blank string
obj.x = tileObjects[x].x; //works fine, gives the value in the json
}
我试图拉的json的具体部分是
"objects":[
{
"gid":21,
"height":0,
"name":"object1",
"properties":
{
"exit":"true"
},
"type":"1",
"visible":true,
"width":0,
"x":63,
"y":57
},
{
"gid":22,
"height":0,
"name":"object2",
"properties":
{
},
"type":"2",
"visible":true,
"width":0,
"x":158,
"y":95
},
{
"gid":16,
"height":0,
"name":"object3",
"properties":
{
},
"type":"3",
"visible":true,
"width":0,
"x":10,
"y":189
},
{
"gid":17,
"height":0,
"name":"object4",
"properties":
{
},
"type":"4",
"visible":true,
"width":0,
"x":156,
"y":227
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"width":20,
"x":0,
"y":0
}],