1
data={"convID":"E40E92FD4B410","serverDate":"2012/06/15 07:51:07 PM","masterInfo":{"instance":"808477149_R_BDD72269D1C1E98A32D8C83EC58CF471","appVersion":"0.97.13.D","depth":4,"jsonURL":"//testtn","scenario":"R","serverDate":"2012/06/15 07:51:07 PM ","deviceName":"M’s","localDate":"2012/5/6 11:14:59 AM PDT"}}

JSON.parse(data);

gives an error. This was generated by JSON.generate in a ruby script and sent to node http server, decodeURIComponent was applied to get the data printed above. still JSON parse fails with this error:

undefined:1
ate":"2012/06/15
^
SyntaxError: Unexpected token d
at Object.parse (native)

1 Answer 1

3

In your code example data is JS object. But JSON.parse takes a string as its parameter, not an object. So your code must be:

data='{"convID":"E40E92FD4B410","serverDate":"2012/06/15 07:51:07 PM","masterInfo":{"instance":"808477149_R_BDD72269D1C1E98A32D8C83EC58CF471","appVersion":"0.97.13.D","depth":4,"jsonURL":"//testtn","scenario":"R","serverDate":"2012/06/15 07:51:07 PM ","deviceName":"M’s","localDate":"2012/5/6 11:14:59 AM PDT"}}';

JSON.parse(data);

So, check the value and the type of data variable in your real code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.