Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON Simple Iteration over Array
    primarykey
    data
    text
    <p>Updated with actual JSON Response, Messed up last time.</p> <p>It is my second day with JSON, and i am stuck at the first step of my project.</p> <p>i created a wcf rest service which gives this test json response.</p> <pre><code>[{ "busyEndTime":"\/Date(928164000000-0400)\/", "busyStartTime":"\/Date(928164000000-0400)\/", "endGradient":1.26743233E+15, "startGradient":1.26743233E+15, "status":"String content" </code></pre> <p>}]</p> <p>i am trying to read the content of this output and use the content for various other purposes. By content i am referring to the "busyEndTime, busyStartTime" values etc.</p> <p>I have tried numerous examples on the net, but my bad luck continues, </p> <p>following are the ways i tried to read the above, but failed.</p> <pre><code>$('#btnGetTime').click(function () { $.ajax({ cache: false, type: "GET", async: false, url: serviceAddress, dataType: "application/json; charset=utf-8", data: "{}", success: function (student) { </code></pre> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>*</strong> Try 1 </p> <pre><code>var obj = jQuery.parseJSON(student); for (var i = 0; i &lt; obj.length; i++) { alert(obj[i]); } </code></pre> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>*</strong> Try 2</p> <pre><code>var obj = eval("(" + student + ")"); for (var i = 0; i &lt; obj.length; i++) { alert(obj[i]); } </code></pre> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>*</strong>*Try 3</p> <pre><code>success: test(student) ....... ..... function test(jObject) { var jArrayObject = jObject if (jObject.constructor != Array) { jArrayObject = new Array(); jArrayObject[0] = jObject; } </code></pre> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>****</strong>*Try 4</p> <pre><code>success: test(student) ....... ..... function test(jObject) { var jArrayObject = jObject for (var i = 1, n = jObject.length; i &lt; n; ++i) { var element = jObject[i]; ................ .................... } </code></pre> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>***</strong> Try5</p> <pre><code> $.each(jArrayObject, function (key, value) { alert(key + ": " + value); }); </code></pre> <hr> <p>I would really appreciate if some one could guide step by step, of how to read the JSON response like i have above and iterate over the array that the response contains and finally use the content that lies in the array, at least alert the key value pairs.</p> <p>A quick response is all i want, i am loosing interest in jquery with each passing minute. :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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