Saturday, March 19, 2016

JSON.parse(), $.parseJSON() Similar Function.


Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all invalid JSON strings:
  • "{test: 1}" (test does not have double quotes around it).
  • "{'test': 1}" ('test' is using single quotes instead of double quotes).
  • "'test'" ('test' is using single quotes instead of double quotes).
  • ".1" (a number must start with a digit; "0.1" would be valid).
  • "undefined" (undefined cannot be represented in a JSON string; null, however, can be).
  • "NaN" (NaN cannot be represented in a JSON string; direct representation of Infinity is also not permitted).

No comments:

Post a Comment