0

From the backend I get a string(nothing I could handle with JSON.parse or JSON.stringify):

"{
  Search_Ids: [
    { "searchId": "428784921" },
    { "searchId": "428784922" },
    { "searchId": "428784923" },
    { "searchId": "428784924" },
    { "searchId": "428784925" }
  ],
  Checksum: 5
}"

I want to convert a JavaScript string to a Javascript object. Using JSON class does not work.

11
  • 1
    "Does not work" is not an adequate problem description. What is the actual behaviour you observe? Commented Jan 15, 2017 at 11:01
  • 3
    It's not a valid string literal, they can't contain line breaks like that. Remove them. And you can't have unquoted double quotes inside double quotes, etc. Commented Jan 15, 2017 at 11:01
  • Is the problem about keys like Search_Ids not quoted in your input? Do you control the backend, is it possible to fix it? Commented Jan 15, 2017 at 11:02
  • 1
    It is also not valid JSON: property names need to be quoted. Commented Jan 15, 2017 at 11:02
  • 1
    assigning the string to a variable without the quotation marks works like this : var x={ Search_Ids: [ { "searchId": "428784921" }, { "searchId": "428784922" }, { "searchId": "428784923" }, { "searchId": "428784924" }, { "searchId": "428784925" } ], Checksum: 5 }; with quation marks at the beginning does not work Commented Jan 15, 2017 at 11:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.