Answer the question
In order to leave comments, you need to log in
Problem in JSON or its parsing method?
Hello.
via Ajax I get JSON like
[{"Employee":"leading specialist","map_list":{"Direction":"New office","DIS":"0"}},{"Employee":"senior specialist", "map_list":{"Direction":"Old office","DIS":"1"}},{"Employee":"boss","map_list":{"Direction":"Virtual office","DIS" :"0"}},{"Employee":"unit_constant","map_list":{"Count":"2","POSTS":"3","NEW":"1"}}]
trying to parse by method
var result = [];
var keys = Object.keys(jsondata);
keys.forEach(function(key){
result.push(json[key]);
});
Answer the question
In order to leave comments, you need to log in
Explicitly says json variable does not exist
var result = [];
var keys = Object.keys(jsondata);
keys.forEach(function(key){
result.push(jsondata[key]);
});
// конвертируем JSON Object в массив
function JSONtoArray(JSONObject) {
var result = [];
for(var k in JSONObject) {
var v = JSONObject[k];
result.push(k, v);
}
return result;
}
$.getJSON( "employees?region="+encodeURI(selected), { selected_region: selected } )
.done(function( jsondata ) {
var result=JSONtoArray(jsondata[3].map_list);
// далее работаем с массивом
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question