答案 0 :(得分:6)
答案 1 :(得分:2)
答案 2 :(得分:0)
一旦你修复了json,它应该看起来像这样,并且像这样工作
var jsonData = {
"XXXX": {
"name": "Dalvin Nieger",
"work": {
"department": {
"name": "Sales"
},
"start_date": "0000-00"
},
"link": "http://www.my-site.com/profile.php?id=XXXXX",
"id": "XXXXXX"
},
"XXXXXXX": {
"name": "Nick Mercer",
"work": {
"department": {
"name": "Marketing"
},
"start_date": "0000-00",
"end_date": "0000-00"
},
"link": "http://www.my-site.com/profile.php?id=XXXXXX",
"id": "XXXXXX"
}
}
$.each(jsonData,function(id,data){
var content = '<p>ID : '+id;
if(typeof data == 'object')
$.each(data,function(index,value){
if(typeof value == 'object' && index=='work'){
content += '<br/>'+index+' : '+value.department.name;
}else
content += '<br/>'+index+' : '+value;
});
content += '</p>';
$('#result').append(content);
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="result">
</div>
&#13;