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

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

巴扎黑
發布: 2016-11-25 13:53:46
原創
2627 人瀏覽過

假設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  

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板