How to read this JSON?
Im sorry if this is a newbie question but I'm getting confuse about how to read this json string:
{
"VF001JV018":[
{
"kode_question":"VF001JV018",
"kode_option":1,
"kode_option_tipe":"PF006",
"nama_option":"Pilihan 1",
"reference_db":null,
"reference_table":null,
"reference_field":null,
"required_value":0,
"reference_pk":null,
"status":1
},
{
"kode_question":"VF001JV018",
"kode_option":4,
"kode_option_tipe":"PF006",
"nama_option":"Pilihan 4",
"reference_db":null,
"reference_table":null,
"reference_field":null,
"required_value":0,
"reference_pk":null,
"status":1
},
开发者_如何学编程 {
"kode_question":"VF001JV018",
"kode_option":5,
"kode_option_tipe":"PF006",
"nama_option":"Lainnya",
"reference_db":null,
"reference_table":null,
"reference_field":null,
"required_value":1,
"reference_pk":null,
"status":1
}
],
"VF001JV020":[
{
"kode_question":"VF001JV020",
"kode_option":1,
"kode_option_tipe":"PF001",
"nama_option":"Kode Toko",
"reference_db":"crm",
"reference_table":"customer",
"reference_field":"kode_customer",
"required_value":0,
"reference_pk":" ",
"status":1
}
]
}
How to show the data in list? for example:
<ul>
<li><strong>VF001JV018</strong></li>
<li>VF001JV018-1</li>
<li>VF001JV018-4</li>
<li>VF001JV018-5</li>
<li><strong>VF001JV020</strong></li>
<li>VF001JV020-1</li>
</ul>
I use jquery each function to loop each element but still no luck
$.getJSON('data.json', null, function(response){
var echo = '<ul>';
$(response).each(function(k,v){
echo += '<li><strong>'+k+'</strong> : '+v+'</li>';
});
echo += '</ul>';
$('#here').html(echo);
});
response
is not a HTML string or DOM element. You cannot pass it to jQuery this way.
Use jQuery.each
to loop over it:
$.each(response, function(k, v) {
echo += '<li><strong>'+k+'</strong></li>';
});
You cannot concatenate the string with v
, as v
is an array again. You have to loop over it and access the specific information you want to print, e.g. v[i].status
.
精彩评论