OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

JSON: Error while Parsing

  • Thread starter Thread starter Muaaz Khalid
  • Start date Start date
M

Muaaz Khalid

Guest
I've the following JSON(Valid) sting.

Code:
[["abc","{\"icon\":\"adjust\",\"prefix\":\"fa\",\"markerColor\":\"red\"}"],["xyz","{\"icon\":\"archive\",\"prefix\":\"fa\",\"markerColor\":\"green\"}"],["azs","{\"icon\":\"asterisk\",\"prefix\":\"fa\",\"markerColor\":\"darkred\"}"]]

it gives error when I try to Parse using the JSON.parse function here is the code that I'm using for parsing.

Code:
JSON.parse('[["abc","{\"icon\":\"adjust\",\"prefix\":\"fa\",\"markerColor\":\"red\"}"],["xyz","{\"icon\":\"archive\",\"prefix\":\"fa\",\"markerColor\":\"green\"}"],["azs","{\"icon\":\"asterisk\",\"prefix\":\"fa\",\"markerColor\":\"darkred\"}"]]');

and it gives an error in console Uncaught SyntaxError: Unexpected token i

here is the Correct Output by same string using online JSON viewer.
Correct Output by same string using online JSON viewer


<p>I've the following <code>JSON</code>(Valid) sting.</p>
<pre><code>[["abc","{\"icon\":\"adjust\",\"prefix\":\"fa\",\"markerColor\":\"red\"}"],["xyz","{\"icon\":\"archive\",\"prefix\":\"fa\",\"markerColor\":\"green\"}"],["azs","{\"icon\":\"asterisk\",\"prefix\":\"fa\",\"markerColor\":\"darkred\"}"]]
</code></pre>
<p>it gives error when I try to Parse using the <code>JSON.parse</code> function
here is the code that I'm using for parsing.</p>
<pre><code>JSON.parse('[["abc","{\"icon\":\"adjust\",\"prefix\":\"fa\",\"markerColor\":\"red\"}"],["xyz","{\"icon\":\"archive\",\"prefix\":\"fa\",\"markerColor\":\"green\"}"],["azs","{\"icon\":\"asterisk\",\"prefix\":\"fa\",\"markerColor\":\"darkred\"}"]]');
</code></pre>
<p>and it gives an error in console <code>Uncaught SyntaxError: Unexpected token i</code></p>
<p>here is the Correct Output by same string using online JSON viewer.
<img src="https://i.sstatic.net/bVHyP.jpg" alt="Correct Output by same string using online JSON viewer" /></p>
 

Latest posts

M
Replies
0
Views
1
Marcos R. Guevara
M
Top