dwitter icon indicating copy to clipboard operation
dwitter copied to clipboard

Comment API error while parsing JSON

Open imscary opened this issue 7 years ago • 3 comments

For example, if I want to parse the responeText of /api/comments/?reply_to=9006, it will fail:

Uncaught SyntaxError: Unexpected token / in JSON at position 87
    at JSON.parse (<anonymous>)
    at <anonymous>:1:13

The problem is at "urlized_text":"<a href="/h/matrix">#matrix</a>" The " before /h/matrix cancels the " after href= causing an error. The best fix is to simply change the " in '

imscary avatar Aug 06 '18 09:08 imscary

When I follow that link, I see "urlized_text":"<a href=\"/h/matrix\">#matrix</a>"

The quotes are properly escaped in the response, so they should parse fine.

joeysino avatar Aug 06 '18 10:08 joeysino

This looks correct to me; maybe your tool is unescaping too early?

lionleaf avatar Aug 07 '18 00:08 lionleaf

It still errors while parsing. the responseText needs to split('\\"').join('"') to parse correctly.

imscary avatar Aug 07 '18 05:08 imscary