How about using value.Address.City and value.Address.Street?? The most common way to access JSON data is through dot notation. This is simply the object name followed by a period and then followed by the name/property you would like to access. http://www.hunlock.com/blogs/Mastering_JSON_%28_JavaScript_Object_Notation_%29
For example,
$.each(data, function(key,value) {
$('#companyDetails').append('<li>'+key+'<span class="ui-li-aside">'+ value.Address.Street + "," + value.Address.City +'</span></li>');
});
For detail coding,
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function display(data) {
$.each(data, function(key,value) {
$('#companyDetails').append('<li>'+key+'<span class="ui-li-aside">'+ value.Address.Street + "," + value.Address.City +'</span></li>');
});
}
$(document).ready(function() {
var data = [
{
"Name" : "ABC",
"Company" : "AA Company",
"Address" : {
"Street" : "123 Main Street",
"City" : "Yangon"
}
},
{
"Name" : "DEF",
"Company" : "BB Company",
"Address" : {
"Street" : "8941 Mandalay",
"City" : "NaypiDaw"
}
}
];
display(data);
});
</script>
</head>
<body>
<div id="companyDetails"></div>
</body>
</html>
For you case that you do not know which data are in json file,
function display(data,flag) {
$.each(data, function(key,value) {
if ($.isPlainObject(value)) {
if(flag == true)
{
$('#companyDetails').append('<b>' + "Company " + (key + 1) + '</b>');
}
display(value,false);
}
else
$('#companyDetails').append('<li>' + key + " : " +'<span class="ui-li-aside">'+ value +'</span></li>');
});
}
In calling display function,
var flag = true;
display(data,flag);
Your output would be
I hope this would help.