I am asking for youtube search terms for use with jquery autocomplete, but I find it difficult to convert the URL response to the correct format.
In my view (Django / Python), I:
data2 = urllib2.urlopen('http://suggestqueries.google.com/complete/search?hl=en&ds=yt&client=youtube&hjson=t&jsonp=window.yt.www.suggest.handleResponse&q=jum&cp=3')
(I just coded the search term = "jump" for simplicity)
If I do data2.read() , I get what I consider JSON (copying to the URL in the browser also returns this.)
window.yt.www.suggest.handleResponse(["jum",[["jumpstyle","","0"],["jump","","1"],["jump around","","2"],["jump on it","","3"],["jumper","","4"],["jump around house of pain","","5"],["jumper third eye blind","","6"],["jumbafund","","7"],["jump then fall taylor swift","","8"],["jumpstyle music","","9"]],"","","","","",{}])
I need to return this in a format that jquery autocomplete can read. I know this will work if I can get it in the list, for example, mylist = ['jumpstyle', 'jump', 'jump around', ...]
and then translate it back to json before returning it:
json.dumps(mylist)
(This works if I directly define mylist directly as above.)
But I canβt get the data that is returned by the URL, either in a simple list (which I then convert back to JSON) or in some form of JSON that I can return directly to use automatic completion.
I tried, by the way,
j2 = json.loads(data2)
and
j2 = json.loads(data2.read())
Hope someone can help!