HTML
<table id="id_kbdata" cellspacing="0" cellpadding="0" >
</table>
JSON
[
{
"id":"3",
"title":"Doing Business In...",
"businessSubjectAreas":[
{
"businessSubjectArea":"Market and Sell Products/Service"
},
{
"businessSubjectArea":"Deliver Products/Services"
},
{
"businessSubjectArea":"HR"
},
{
"businessSubjectArea":"Legal"
},
{
"businessSubjectArea":"Finance"
},
{
"businessSubjectArea":"Tax"
},
{
"businessSubjectArea":"Treasury"
},
{
"businessSubjectArea":"IT"
}
],
"attachmentFiles":[
{
"fileName":"test.pdf",
"url":"http://google.com/test.pdf"
}
],
"error":null
},
{
"id":"65",
"title":"Dialing Instructions",
"businessSubjectAreas":[
{
"businessSubjectArea":"Administrative"
}
],
"attachmentFiles":[
],
"error":null
},
{
"id":"132",
"title":"WA - Western Australia - Drilling Fluid Management",
"businessSubjectAreas":[
{
"businessSubjectArea":"Market and Sell Products/Service"
},
{
"businessSubjectArea":"Deliver Products/Services"
},
{
"businessSubjectArea":"Legal"
}
],
"attachmentFiles":[
{
"fileName":"test.pdf",
"url":"http://google.com/test.pdf"
}
],
"error":null
},
{
"id":"133",
"title":"WA - Natural gas from shale and tight rock - Overview of WA regulatory framework",
"businessSubjectAreas":[
{
"businessSubjectArea":"Market and Sell Products/Service"
},
{
"businessSubjectArea":"Deliver Products/Services"
},
{
"businessSubjectArea":"Legal"
}
],
"attachmentFiles":[
{
"fileName":"test.pdf",
"url":"http://google.com/test.pdf"
}
],
"error":null
}
]
Here I am trying to loop through above JSON response and append the resulted values in HTML table. But unable to do it, below is what I tried so far.
Actually I am confused how to use the nested values from JSON like "businessSubjectArea". I just wanted to append the values in table td's and nested values in li's
$.each(json, function(index, value) {
$("#id_kbdata").append(
" <tr><td style='text-align:left;font-family:arial;padding:5px 10px;border-bottom:1px solid #ccc;border-right:1px solid #ccc;width:33%;'>"
+ this.title +
"</td><td style='text-align:left;font-family:arial;padding:5px 10px;border-bottom:1px solid #ccc;border-right:1px solid #ccc;width:33%;'> "
+ "<ul>" +
$.each(this.businessSubjectAreas, function(index, value) {
"<li>" + this.businessSubjectAreas.businessSubjectArea + "</li>"
});
+ "</ul>" +
" </td></tr>"
);
});
Any help would be highly appreciated.