Answer the question
In order to leave comments, you need to log in
How to parse multidimensional JSON?
I have a JSON file:
{
"a":{"x":"y","x1":"y1","x2":"y2"},
"b":{"z":"c","z1":"c1","z2":"c2"}
}
$.getJSON('bt.json', function (data) {
var items = [];
$.each(data, function (key, val) {
items.push('<option id="' + val + '" value="'+val+'">' + key + '</option>');
});
$('<select/>', {
'class': 'my-new-list',
html: items.join("")
}).appendTo('.model');
Answer the question
In order to leave comments, you need to log in
Probably so
$.getJSON('bt.json', function (data) {
var items = [];
$.each(data, function (val) {
$.each(val, function (key, val) {
items.push('<option id="' + val + '" value="'+val+'">' + key + '</option>');
});
});
$('<select/>', {
'class': 'my-new-list',
html: items.join("")
}).appendTo('.model');
Thank you, I need to do something like this:
$.getJSON('ko.json', function (data) {
var items = [];
$.each(data, function (key,val) {
$.each(val, function (key1, val1) {
if (key=='bt'){items.push('<option id="' + val1 + '" value="' + val1+ '">' + key1 + '</option>');}
});
});
$('<select/>', {
'class': 'my-new-list',
html: items.join("")
}).appendTo('.model');
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question