首頁  >  文章  >  web前端  >  取得Json物件的長度以及判斷json物件是否為空

取得Json物件的長度以及判斷json物件是否為空

巴扎黑
巴扎黑原創
2016-11-25 13:53:462595瀏覽

假設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程式碼  

function getJsonObj1ength(jsonOb  

    for (var item in jsonObj ) {  

        Length++;  

    }  

  到。

Js程式碼  

alert(getJsonObjLength(str)) //2  



= = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = 詞

= = = = = = = = = = = = = = = = = = = = = //a, b  

    alert(json[key]); //12, 45  

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn