我收到此错误信息:JSON.parse数组元素嵌套不工作
SyntaxError: JSON.parse: expected ',' or ']' after array element at line 4 column 18 of the JSON data.
我想是因为我有一个数组中的对象,也许这是不允许的。但我需要经验丰富的开发人员对此进行确认。你可以把对象放在json数组中吗?
HTML
<div id="ex1"><h2>Example 1</h2><p></p><h4>results:</h4></div>
的Javascript
var message;
(function loadAjax()
{ var request;
if (window.XMLHttpRequest)
{
request = new XMLHttpRequest();
}
else{
request = new ActiveXObject('Microsoft,XMLHTTP');
}
request.open('GET','human.json');
request.onreadystatechange = function()
{
if(request.readyState == 4 && request.status == 200)
{
message = request.responseText;
var obj = JSON.parse(message);
var text = obj.job[0].hospital;
attach('ex1',text,'p');
}
}
request.send();
})();
JSON
{
"sex":{"male":{"fname":["Michael","Tom"]} ,"female":{"fname":["Alice","Katie"]}},
"age":[16,80],
"job":["medical":{"hospital": "doctor"}, "education":{"school":"teacher"} ]
}
你的'job'属性包含无效的类似assotiative的数组,其中包含像'medical'和'education'这样的类似对象的键。有效数组的一个例子是具有'age'键的属性。'job'属性可能应该包含一个对象而不是数组。 –
你刚刚在其他地方发布。为什么不让他们在同一个问题? http://stackoverflow.com/questions/37017756/json-parse-expected-or-after-property-value-in-object/37017795#37017795 –
@Wes Foster,这实际上是一个关于我有一个数组的问题JSON。但是,我不知道你可以继续添加上一个你已经提出的问题 –