JSON objects vary and are very flexible, and the corresponding fetch methods are:
1. The simplest type (MyObject is an object, not a string oh)
<script type= "Text/javascript" > var myObject = {' name ': ' Kasun ', ' address ': ' Columbo ', ' Age ': ' $ '} var Count = Object.keys (myObject). Length Console.log (count);</script>
In older browsers, you need to include the following code to make sure you can use:
if (! Object.keys) { Object.keys = function (obj) { var keys = [], K; for (k in obj) { if (Object.prototype.hasOwnProperty.call (obj, k)) { keys.push (k); } } return keys; };}
The form of the value returned by the 2.ajax request:
{"Reqstatus": true, "Phones": {"one": {"number": "Xxxxxxxxxx", "type": "Mobile"}, "one": {"number": "Xxxxxxxxxx", "type": "Mobile"}}}
Traverse it:
var key, Count = 0;for (key in Data.phones) { if (Data.phones.hasOwnProperty (key)) { count++; }}
3. More Methods StackOverflow
Http://stackoverflow.com/questions/6756104/get-size-of-json-objecthttp://stackoverflow.com/questions/126100/ how-to-efficiently-count-the-number-of-keys-properties-of-an-object-in-javascript/4889658#4889658
Get JSON object length