I'm trying to parse text from facebook json file which has nested arrays, but i get only the elements of first level of array. I want to get and the data from nested array, if exists. For example using the code above, i can't get the fields in arrays "category_list".
Example of data is
{
"userdata": [
{
"category": "Community",
"name": "whitespace",
"created_time": "2014-01-30T13:58:22+0000",
"id": "xxxxxxxxxxxxxxxxxx"
},
{
"category": "City",
"category_list": [
{
"id": "xxxxxxxxxxxxxxxxxx",
"name": "City"
}
],
"name": "Marburg, Queensland",
"created_time": "2014-01-09T13:09:14+0000",
"id": "xxxxxxxxxxxxxxxxxx"
},
{
"category": "Hotel",
"name": "Hotel Line",
"created_time": "2014-01-06T20:41:44+0000",
"id": "xxxxxxxxxxxxxxxxxx"
},
{
"category": "Food/beverages",
"name": "Olive",
"created_time": "2014-01-06T20:41:16+0000",
"id": "xxxxxxxxxxxxxxxxxx"
},
{
"category": "Education",
"name": "Genius Solutions Group",
"created_time": "2014-01-06T20:40:48+0000",
"id": "xxxxxxxxxxxxxxxxxx"
},
{
"category": "Hotel",
"category_list": [
{
"id": "128232937246338",
"name": "Travel & Transportation"
}
],
"name": "Seabreeze",
"created_time": "2014-01-06T20:40:07+0000",
"id": "xxxxxxxxxxxxxxxxxx"
},
{
"category": "Local business",
"category_list": [
{
"id": "xxxxxxxxxxxxxxxxxx",
"name": "Computer Store"
}
],
"name": "Project",
"created_time": "2014-01-06T20:38:26+0000",
"id": "xxxxxxxxxxxxxxxxxx"
},
{
"category": "Tv show",
"name": "helloooo",
"created_time": "2014-01-06T20:38:08+0000",
"id": "xxxxxxxxxxxxxxxxxx"
}
]
}
The code i use is
<html>
<head>
<title>Parsing</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">
</script>
</head>
<body>
<a href="#" id="loaduserdata">User Data</a>
<table id="userdata" border="1">
<thead>
</thead>
<tbody></tbody>
</table>
<script>
$(document).ready(function(){
});
$("#loaduserdata").click(function(){
$("#userdata tbody").html("");
$.getJSON(
"jsondata.php",
function(data){
$.each(data.userdata, function(i,user){
var tblRow =
"<tr>"
+"<td>"+user.category+"</td>"
+"<td>"+user.name+"</td>"
+"</tr>"
$(tblRow).appendTo("#userdata tbody");
});
}
);
});
</script>
</body>
</html>
and results are
User Data
+----------------+------------------------+
| Community | whitespace |
| City | Marburg, Queensland |
| Hotel | Hotel Line |
| Food/beverages | Olive |
| Education | Genius Solutions Group |
| Hotel | Seabreeze |
| Local business | Project |
| Tv show | helloooo |
+----------------+------------------------+
Some help please...