以下是獲取json的元素數量的代碼:
<script>
var keleyijson={"plug1":"myslider","plug2":"zonemenu","plug3":"keleyi"}
function JSONLength(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
document.write("json對象的元素個數是:"+JSONLength(keleyijson));
</script>
效果如下: