Answer the question
In order to leave comments, you need to log in
How to change such a JSON parser?
Greetings, please help me how to change such a parser to JSON for a new server response.
Old server response:
{"names":[{"name":"Oleg","act":0,"total":0},{"name":"Vitya","act":2,"total":2}]}
names = appData.filter( function(x) { return skipped.indexOf(x) < 0; })
get("https://serv.io/set?" + names.join("|")).then(function(data) {
result = JSON.parse(data)["names"]
for (var i = 0; i < result.length; i++) {
name = result[i]["name"]
act = result[i]["act"]
total = result[i]["total"]
}
{"Oleg":{"act":0,"total":0},"Vitya":{"act":2,"total":2}}
Answer the question
In order to leave comments, you need to log in
names = appData.filter(function (x) { return skipped.indexOf(x) < 0; })
get("https://serv.io/set?" + names.join("|")).then(function (data) {
result = JSON.parse(data);
Object.entries(result).forEach(([name,{act, total}])=>{
console.log(name,act,total) // переменные name,act,total тут локальны, но сами уже разберетесь
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question