samedi 21 août 2021

How can I change such a JSON parser?

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}]}

Old parser:

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"]
          }

New server response:

{"Oleg":{"act":0,"total":0},"Vitya":{"act":2,"total":2}}

As you can see in the new answer, as I understand it, there is no array and here the name is as the name of the object. The question is how to change the old parser for the new server response. I would be grateful for your help!




Aucun commentaire:

Enregistrer un commentaire