javascript json prase get key by index get value by index

<html>
<body>

<script type="text/javascript">
Object.prototype.k = function(n){
       var arr = [];   
       for(pro in this) arr.push(pro);
       return arr[n]
}
Object.prototype.v = function(n){
       var arr = [];
       for(pro in this) arr.push(pro);
       return n < arr.length-1 && this[arr[n]]
}
 
var jsonObject = {"UserID":11, "Name":{"FirstName":"John","LastName":"Hansen"}, "Email":"[email protected]"};
alert(jsonObject.k(0));
alert(jsonObject.k(1));
alert(jsonObject.v(1).k(0));
alert(jsonObject.v(1).k(1));
alert(jsonObject.k(2))

alert(jsonObject.v(0));
alert(jsonObject.v(1));
alert(jsonObject.v(1).v(0));
alert(jsonObject.v(1).v(1));
alert(jsonObject.v(2))
</script>
</body>

</html>


测试网址: http://www.w3school.com.cn/tiy/t.asp?f=jseg_text

你可能感兴趣的:(javascript json prase get key by index get value by index)