Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you familiar with JavaScript objects and arrays? Because that's basically all JSON is. (Not being condescending; I was only able to make sense of XML when I learned HTML, and I only got JSON after I learned JS.)</p> <p>Once you understand JS objects/arrays, if you're going to work with the JSON in PHP, you'll need to understand that JS arrays are basically the same as PHP arrays, and that JS objects are basically the same as PHP associative arrays.</p> <p>The final piece is the function: When you get the JSON, it's probably just a string. If you're using PHP 5.2, you'll have access to <a href="http://php.net/manual/en/function.json-decode.php" rel="nofollow"><code>json_decode</code></a>, which converts the JSON to arrays/associative arrays.</p> <p>If I'm just repeating stuff you already knew and this was no help at all, then you'll probably have to go into more detail as to what your problem is.</p> <p><strong>EDIT</strong><br> After reading your comments on the other answer, it sounds like you're trying to do the following:</p> <ol> <li>get the JSON into PHP, then</li> <li>send that JSON from PHP to JavaScript, and</li> <li>manipulate the JSON with JavaScript. </li> </ol> <p>Is this correct? If it is, then almost everything I said earlier is useless. You'll probably want to start with <a href="http://php.net/manual/en/function.file-get-contents.php" rel="nofollow"><code>file_get_contents</code></a>. All you have to do is give it the URL of the JSON, and it will return the JSON as a string.</p> <p>Now, if you're just getting it with PHP so that you can send it straight to the JavaScript, then the string is all ready to go. Just <code>echo</code> it out in a way that the JS can handle:</p> <pre><code>&lt;script&gt; var data = &lt;?php echo $JSON ?&gt;; &lt;/script&gt; </code></pre> <p>Note that the biggest problem with this is that it doesn't do <em>any</em> security checking at all. You'll probably be fine, but just keep that in mind.</p>
 

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