Assume that json is:
Json code
[{"name":'a',"age":1,"sex":"0","title":"hello","state":"0","id":"1"},{"name":'b',"age":2,"sex":"1","title":"bye","state":"0","id":"2"}]
The following is the method to get the length of the json object:
Js code
function getJsonObjLength(jsonObj) { var Length = 0; for (var item in jsonObj) { Length++; } return Length; }
You can get it through this method.
Js code
alert(getJsonObjLength(str)) //2
= = = = = = = = = = = = = = Determine whether the json object is empty = = = = = = = = = = = = = = = =
Js code
var json={a:12,b:45} for(var key in json){ alert(key); //a, b alert(json[key]); //12, 45 }