|
What is JSON
|
|
06-20-2009, 07:26 AM
Post: #1
|
|||
|
|||
|
What is JSON
I know very little about JSON but I'm wondering what its uses are and why someone would use it. I do a bit of AJAX with JQuery and I'm wondering if I should be using JSON with it.
|
|||
|
06-20-2009, 08:53 AM
Post: #2
|
|||
|
|||
|
RE: What is JSON
JSON is basically a convenient way to store/organize data in combination with AJAX stuff. JSON means Javascript Object Notation. If you know how objects are easily constructed in Javascript, you can probably work with JSON pretty quickly.
jQuery works nicely with JSON in doing AJAX requests. Here's a typical scenario I use it for: 1. Send a POST request with jQuery to my PHP backend (an AJAX requset) 2. Have my PHP code deal with the request and generate a JSON object to return to the client. 3. The Javascript is ready to work with the object right away and use its data. PHP 5.2 and higher has a nice set of 3 JSON functions: http://us3.php.net/manual/en/ref.json.php So what I do in step 2 is get my data ready, then I use json_encode to generate a JSON object. I echo that object, then, and the jQuery reads that response. If you specify "json" as an argument in the jQuery request, you don't even need to run eval() on it, and you can just use the object as it comes. More info here: http://www.json.org - Matt codeboards Admin |
|||
|
« Next Oldest | Next Newest »
|

Search
Member List
Calendar
Help



