This code fails with an exception indicating invalid JSON:
var example = '{ "AKEY": undefined }';
jQuery.parseJSON(example);
I was able to fix it by replacing all undefineds with empty strings. Are undefineds not part of JSON?
This code fails with an exception indicating invalid JSON:
I was able to fix it by replacing all undefineds with empty strings. Are undefineds not part of JSON? |
|||
|
If you can wrap your head around this, the token Allow me to elaborate: even though JavaScript has a special primitive value called undefined,
The only console output will be 'no AKEY'. After we've assigned to the global variable You probably want to explicity set You could also simply omit
(If you set The only real difference between setting to null and omitting is whether you want the key to appear in a foreach loop. |
|||
|
No, but
|
|||
|
Correct. Undefined and functions are not represented in JSON. http://www.json.org/js.html |
|||
|
They're not permitted in JSON...look at the alternative and it's clear as to why:
If it's |
|||||||||||||
|