In addition to fetching JSON you might want to POST it back to the
server, but there is no postJSON method. You cannot use the generic
ajax method, either. What is missing is the complement of "eval" to
turn a JavaScript object in to JSON. The JSON.stringify function from
www.json.org (see json2.js in JavaScript section) does the trick, but
it would be nice if jQuery incorporated that out of the box, to save
some hunting time.

Using the jquery ajax method to set the "type" to "json" and the
"content-type" to "application/json" send and recieve JSON, but you
must use JSON.stringify to convert your outgoing object to JSON.

P.S.. a lot of forgiving parsers have resulted in a lot of articles on
JSON being wrong. would I like to mention that here. Property names
are JSON strings. JSON strings have double quotes. Therefore, property
names have to be surrounded with double quotes. Single quotes are not
JSON strings and not legal (JSON is not JavaScript).

INVALID: { foo : "bar" }
INVALID: { 'foo' : "bar" }

VALID: { "foo" : "bar" }

VALID: { "foo" : true, "bar" : 98.6, "baz" : [ 1, 2, 3 ], "waldo" :
{ "cheese" : "blue" }  }

http://www.json.org

http://www.jsonlint.com/

Reply via email to