Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can do it very easily:</p> <pre><code>for(i = 0; i &lt; msg.count; i++) { alert(msg[i]['name']); } </code></pre> <p>But the structure of your JSON object is not that good for several reasons:</p> <ul> <li><p>It does not reflect the structure of the actual data<br> With this I mean, that you actually have an <strong>array</strong> of objects. But in your JSON object the elements of the array are represented as <strong>properties</strong> of an object.</p></li> <li><p>You have invalid JavaScript object property names.<br> Properties for objects in JavaScript are not allowed to start with numbers. But with <code>msg = { "1": {...}}</code> you have a number as property.<br> Fortunately it is not that bad because you can access this property with "array like" access <code>msg["1"]</code> (instead of the "normal way", <code>msg.1</code>). But I would consider this as bad practice and avoid this as much as possible.</p></li> </ul> <hr> <p>Hence, as Matthew already proposes, it would be better to remove the <code>count</code> entry from the array <strong>on the server side, <em>before</em></strong> you sent it to the client. I.e. you should get a JSON array:</p> <pre><code>[{ "tel1": "Ahemdabad", "status": "1", // etc. }, { "tel1": null, "status": "1", // etc. }] </code></pre> <p>You don't need <code>count</code> as you can get the length of the array with <code>msg.length</code> and you can traverse the array with:</p> <pre><code>for(var i in msg) { alert(msg[i].name); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload