Angenommen, JSON ist:
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"}]
Die folgende Methode lautet, um die Länge des JSON-Objekts zu ermitteln:
Js Der Code
function getJsonObjLength(jsonObj) { var Length = 0; for (var item in jsonObj) { Length++; } return Length; }
kann über diese Methode abgerufen werden.
Js-Code
alert(getJsonObjLength(str)) //2
= = = = = = = = = = = = = = = Bestimmen Sie, ob das JSON-Objekt leer ist = = = = = = = = = = = = = = = = = = =
Js-Code
var json={a:12,b:45} for(var key in json){ alert(key); //a, b alert(json[key]); //12, 45 }