How to loop through an JSON associative array in javascript?

前端 未结 6 745
遥遥无期
遥遥无期 2021-02-04 10:50

I\'m getting a JSON response from the server and i have to loop through the array in javascript and get the values. But I cant seem to loop throught it.

The JSON respons

6条回答
  •  庸人自扰
    2021-02-04 10:56

    You don't need to do like that, dealing with string is a boring job. You can make a object through the response. 1:json = eval(xmlHttp.responseText);

    but this is unsafe in some degree.

    1. json = JSON.parse(xmlHttp.responseText, function(key,value){// can do some other stuff here.});

    then you can operate the variable as a normal object like this obj.a or obj["a"].

    May this will help you.

提交回复
热议问题