I have several AJAX calls to web services in an ASP.Net application, basically I am using JQuery to make the calls but I would like to know the difference (if any) between writing:
data: "{ 'myParameter' : 77 }"
and
data: "{ myParameter : 77 }"
I have tried both approaches and they work so what’s the difference?
Edit 1
Ok so according to my understanding, they are valid because they are valid in JavaScript but they are not strictly JSON valid objects, so what’s the best practice or the recommended use?
Neither of them are actually valid JSON (which requires that all key names are double-quoted with
"). If you’re parsing them later on withevalin JavaScript (which used to be the norm), there’s no visible difference, because all three (single quotes, double quotes, and no quotes) are valid in JavaScript object literals – butevalis a really bad way to parse JSON, especially now thatJSON.parseexists.You should use
JSON.stringifyand produce valid JSON.