One, for the standard JSON objects such as:
var result=[{"Flag": 1, "MacId": "2", "Mbid": 0, "userName": "XXX"},{"flag": 1, "MacId": "1", "Mbid": 1, "UserName" : "YYY"}];
When traversing, you can iterate through the array directly with a for loop, in one of two ways:
1. for(vari = 0; i < result.length; i++) { //Result[i] means that the first JSON object is obtained as Jsonobject //Result[i] The value of the specified field can be obtained by using the. Field nameResult[i].username; }2. for(varIinchresult) { //represents the traversal of an array, and I represents the subscript value of an array , //Result[i] means that the first JSON object is obtained as Jsonobject //Result[i] The value of the specified field can be obtained by using the. Field nameResult[i].username; }
Second, for non-standard JSON objects such as:
var result={"Datas": [{"Flag": 1, "MacId": "2", "Mbid": 0, "userName": "XXX"},{"flag": 1, "MacId": "1", "Mbid": 1, " UserName ":" YYY "}]};
The standard JSON array format ({},{}) must be parsed before traversing.
var data= Result.datas;
1. for(vari = 0; i < data.length; i++) { //Data[i] means that the first JSON object is obtained as Jsonobject //Data[i] The value of the specified field can be obtained by using the. Field nameData[i].username; }2. for(varIinchdata) { //represents the traversal of an array, and I represents the subscript value of an array , //Data[i] means that the first JSON object is obtained as Jsonobject //Data[i] The value of the specified field can be obtained by using the. Field nameData[i].username; }
Note: If you do not print it, first convert the JSON data to the object first, using the function json.parse (JSON data)
Big talk front-end parsing JSON objects