Doubts in the myjson

Asked

Viewed 30 times

1

I would like to use this code on the site myjson.com but give me the error Error: Your JSON appears to be invalid.. How should I do?

[{        
    "imagem": '<a href="http://bit.ly/1r1QIF4" target="_blank">Clique aqui para ver o local</a>'
}]

1 answer

0


The JSON format/syntax defines that keys and values have to be quote strings and not plicas. So you need to escape the quotes that are in the middle of the string like this:

"<a href=\"http://bit.ly/1r1QIF4\" target=\"_blank\">Clique aqui para ver o local</a>"

outworking: http://myjson.com/51bzy

You can also swap the quotes inside the string by quotes. In this case it looks like this:

"<a href='http://bit.ly/1r1QIF4' target='_blank'>Clique aqui para ver o local</a>"

and the site also works: https://api.myjson.com/bins/2w67y

A tool that I use a lot and that indicates errors in JSON is the http://jsonlint.com/, by the creator of the JSON format himself.

  • thanks, but when using "<a href='http://bit.ly/1r1QIF4' target='_blank'>Clique aqui para ver o local</a>" turned out to be " \u003ca href=\"http://bit.ly/1r1QIF4\" target=\"_blank\" \u003e Clique aqui para ver o local \u003c/a\u003e" and then I couldn’t use it. what I do?

  • @Natanaeljunior ah, I see. Then use the first example or use decodeURI(essaString);

  • 1

    thank you I got.....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.