-2

I am trying to parse the following JSON string that is being returned to me but am getting an unexpected identifier error in the console.

"{"title":"MyApp Companion","push_hash":"ff06b5b775e45409f9ab470b64d672d0","t":"mr","alert":"Ryjjgv","n":"Foo Bar","action":"open the app at specific location","pid":"7V8meRCJaj","badge":"Increment"}" 

I am using zepto but the method $.parseJSON() throws the error.

RyanP13
  • 7,413
  • 27
  • 96
  • 166

4 Answers4

4

You might have to escape quotes in your string as your string looks like this:

"your string("your string")"

It should be something like:

"your string(\"your string\")" 

or 'your string("your string")'

or: Remove your first and last quotes

Hope this helps.

Kush
  • 909
  • 1
  • 8
  • 14
3

remove your first and last " or replace with '

"{
    "title": "MyApp Companion",
    "push_hash": "ff06b5b775e45409f9ab470b64d672d0",
    "t": "mr",
    "alert": "Ryjjgv",
    "n": "Foo Bar",
    "action": "open the app at specific location",
    "pid": "7V8meRCJaj",
    "badge": "Increment"
}"

to

 '{
        "title": "MyApp Companion",
        "push_hash": "ff06b5b775e45409f9ab470b64d672d0",
        "t": "mr",
        "alert": "Ryjjgv",
        "n": "Foo Bar",
        "action": "open the app at specific location",
        "pid": "7V8meRCJaj",
        "badge": "Increment"
    }'

and there is on online TOOL jsonlint.com , to validate your JSON

Sarath
  • 9,030
  • 11
  • 51
  • 84
1

Because you're using " to delimit the string literal, the console is parsing the " inside the string as a string delimiter. Try using ' as to delimit the literal:

'{"title":"MyApp Companion", ... }'

Alternatively, you can escape all the " inside the string with \:

"{\"title\":\"MyApp Companion\", ... }"
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
-1

Try this:

$.parseJSON('{"title":"MyApp Companion","push_hash":"ff06b5b775e45409f9ab470b64d672d0","t":"mr","alert":"Ryjjgv","n":"Foo Bar","action":"open the app at specific location","pid":"7V8meRCJaj","badge":"Increment"}')
Andrew
  • 5,290
  • 1
  • 19
  • 22