Sep 24, 2018

[HDGEM] JSON.parse() expects a string and not an array.

When given an array or any other non-string value, JSON.parse() method will automatically coerce it to a string and proceed instead of throwing immediately. From the spec:

  1. Let JText be ToString(text).
  2. ...

The string representation of an array consists of its values, delimited by commas. So

  • String(['1234']) returns '1234',
  • String(['1234as']) returns '1234as', and
  • String(['123', '123']) returns '123,123'.

Notice that string values are not quoted again. This means that ['1234'] and [1234] both convert to the same string, '1234'.

Posted By Blogger to HDGEM at 5/07/2017 03:45:00 AM