Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON Jquery Array type
    primarykey
    data
    text
    <p>I have a basic question on JSON Jquery, and it seams I am sort of stuck some at a point of extracting array objects. My Code below is in javascript, and I just wanted some clarifications as what I might be doing wrong here.</p> <pre><code>&lt;?php $nor = $_SESSION["north"]; $sou = $_SESSION["south"]; $eas = $_SESSION["east"]; $wes = $_SESSION["west"]; session_destroy(); ?&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;jQuery JSON test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var north = "&lt;?php echo $nor ?&gt;"; var south = "&lt;?php echo $sou ?&gt;"; var east = "&lt;?php echo $eas ?&gt;"; var west = "&lt;?php echo $wes ?&gt;"; document.write(north,south,east,west); $(document).ready(function(){ alert("begin loop"); $.getJSON('http://api.geonames.org/earthquakesJSON?north=' + north + ' &amp;south=' + south + '&amp;east=' + east + '&amp;west=' + west +'&amp;callback=?', function(data){ alert(data.earthquakes); }); }) &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So when I use alert(data.earthquakes); I get undefined operation, which is fine but I know here I am getting a response back. However the architecture of the JSON is as following:</p> <pre><code>{"earthquakes": [ {"eqid":"2007hear","magnitude":8.4,"lng":101.3815,"src":"us","datetime":"2007-09-12 09:10:26","depth":30,"lat":-4.5172}, {"eqid":"2007aqbk","magnitude":8,"lng":156.9567,"src":"us","datetime":"2007-04-01 18:39:56","depth":10,"lat":-8.4528}, {"eqid":"2007hec6","magnitude":7.8,"lng":100.9638,"src":"us","datetime":"2007-09-12 21:49:01","depth":10,"lat":-2.5265} ]} </code></pre> <p>So I have tried different ways of extracting information such as <code>alert(data.earthquakes[1].eqid);</code> and <code>alert(data.earthquakes.eqid[1]);</code>, however I am not getting the dedicated array as wanted. </p> <p>Could someone direct me as </p> <ol> <li>how to get the desired architecture result appropriately and </li> <li>if I want to use array and for loop to extract all the elements into local array, </li> </ol> <p>how to do that?</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.
    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