Frage

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.

War es hilfreich?

Lösung 2

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

Andere Tipps

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.

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\", ... }"

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"}')
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top