-4
var Download = request.download; // a["{\"status\":\"success\",\"data\":\"no\"}"] // String

How can parse this string?

Mr Online
  • 21
  • 4
  • Possible duplicate of [Safely turning a JSON string into an object](https://stackoverflow.com/questions/45015/safely-turning-a-json-string-into-an-object) – Robert Moskal Jun 21 '17 at 14:24
  • `var a = a["{\"status\":\"success\",\"data\":\"no\"}"]` is invalid JavaScript. Declaring `var a` in the same statement where you're trying to access a key which is JSON (which makes no sense), will throw `Uncaught TypeError: Cannot read property '{"status":"success","data":"no"}' of undefined` – Patrick Roberts Jun 21 '17 at 14:24

2 Answers2

0

I'm not sure I get what you are trying to do here, but I will assume that you want to parse the string into an object:

var string = "{\"status\":\"success\",\"data\":\"no\"}";
var obj = JSON.parse(string);

If you really want an array, you can look this StackOverflow post to convert you're object into an array.

François Noël
  • 426
  • 4
  • 13
-1

To parse that string just use JSON.parse(). Run a js console and try this

JSON.parse("{\"status\":\"success\",\"data\":\"no\"}");

That will return a js object.

franzke
  • 517
  • 1
  • 6
  • 18