假設json為:
Json代碼
[{"name":'a',"age":1,"sex":"0","title":"hello","state":"0","id":"1"},{"name":'b',"age":2,"sex":"1","title":"bye","state":"0","id":"2"}]
以下是獲取json物件的長度的方法:
Js代碼
Js代碼
function getJsonObjLength(jsonObj) { var Length = 0; for (var item in jsonObj) { Length++; } return Length; }
Js代碼
alert(getJsonObjLength(str)) //2