Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't figure out a way to escape quotes in json in YouTube API

I am using the YouTube API and I'm using Python urllib2.urlopen() to send a GET request. Then I pass the result to Javascript. (I'm using Django)

So, something like this:

result = urllib2.urlopen('https://gdata.youtube.com/feeds/api/videos?'+query+'&max-results=1&alt=json')

I'm using jQuery to parse the JSON formatted response, however some YouTube videos/descriptions have double quotes and this breaks the parseJSON() function.

Any help would be highly appreciated.

like image 520
volk Avatar asked Nov 04 '22 18:11

volk


1 Answers

the error was on my end (obviously) ..the error started with the fact that I didn't realize Django automatically escapes HTML characters due to security, and I hacked my own way of ignoring special HTML chars like & quot; which ended up malforming the json.

the easy fix (in case anybody uses django and ever runs into this problem) to escape special HTML chars is with {{ var|safe }} ..

like image 182
volk Avatar answered Nov 12 '22 11:11

volk