lostpacket
lostpacket

Reputation: 1401

Unexpected Token JSON.parse

I am trying to parse this text coming from server

var s = "{\"server\":DSL01,\"item\":101,\"data\":[[1357849366000,null],[1357849485000,null]}";
JSON.parse(s);

In the console I get following error, Unexpected token D

I need to convert this into a json object.

Upvotes: 0

Views: 5231

Answers (1)

Joseph
Joseph

Reputation: 119877

Because DSL01 should be a string, and therefore wrapped in ""

"{\"server\":\"DSL01\",\"

Also, you lack a ] on the last part, for closing data array.

I suggest you programmatically create your JSON rather than hand-crafting it. That way, you don't make such errors.

Upvotes: 3

Related Questions