How to convert string or javascript string to object json? [duplicate]

1

Through a request to a web service I get this result:

It is a string or string of javascript and I want to convert that result to a json object. I am trying it in the following way, but I still do the same:

var obj = JSON.parse(JSON.stringify(data.return));
    
asked by Marck Vit 12.07.2016 в 16:32
source

2 answers

2

You are converting first to string and then to object that's why it gives you the same result since they are inverse operations. Instead, convert to object only and you will have the result you expect.

var obj = JSON.parse(data.return);
    
answered by 12.07.2016 / 16:42
source
1

You have a call to stringify.

The stringify method converts an object to a JSON string (which is what you already have), while the parse method performs the inverse conversion.

It should be enough with:

var obj = JSON.parse(data.return);
    
answered by 12.07.2016 в 16:38