1

I am facing issue parsing JSON String on the front-end. The parameter result represents a String

function handleresult (result,event){
var newResult  = JSON.stringify(result);
var temp = JSON.parse(newResult);
}

So now the temp variable contains a JSON object which looks like this with escape quotes and ampersand characters, {& quot ;message& quot;:& quot;Cannot find entity by key: 'A0000002'.",& quot;errorCode& quot;:& quot;53610040& quot;}.

But what i want is something like this so that i can parse the key/value pair inside the JSON: {"message":"Cannot find entity by key: 'A0000002'.","errorCode":"53610040"}.

I have tried using the JSON.replace(/& quote ;/g,'"') method, but it does not replace the " character.

Please if someone can tell me what can i do to fix this problem?

Note : There is "/& quot ; " which i want to replace

3

Don't call JSON.stringify() - it expects a JSON object, not a result string. Just call JSON.parse() Like so:

function handleresult (result,event){
var newResult  = JSON.parse(result);

Docs are here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.