I am getting this error message:
SyntaxError: JSON.parse: expected ',' or ']' after array element at line 4 column 18 of the JSON data.
I think it is because I have an object within an array, and maybe that is not allowed. But I need confirmation of this from experienced developers. Can you put objects in arrays in 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"} ]
}
jobproperty contains invalid assotiative-like array with object-like keys such asmedicalandeducation. An example of a valid array is the property with theagekey. Thejobproperty should probably contain an object instead of array.