Home  >  Article  >  Web Front-end  >  Example of js parsing json and reading entity objects in List_javascript skills

Example of js parsing json and reading entity objects in List_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:55:462100browse

1. To pass the background action to the front desk, you need to convert the map into json format

Copy the code The code is as follows:

Map resultMap;
JSONObject json = JSONObject.fromObject(resultMap);
message = json.toString();

Store multiple items in List student object

2. In the front-end js, first convert the resulting json string into an object
Copy code The code is as follows:

var obj = eval("(" data ")");

3. Traverse the objects in the list
Copy code The code is as follows:

for(var key in obj){ //The first level of loop gets each list
var List = obj[key];
for(var student in List){ //The second level loop takes the objects in the list
alert(List[student ].id);
alert(List[student ].name);
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn