JSON

I can't resist...

This is a good place to start:

http://screen.yahoo.com/_xhr/slate-data/?list_id=7b1cbcc0-897a-4f19-a276-833534e9dd8d&start=3&count=21&u1_tlen=50&u1_slen=100&u2_tlen=100&u2_slen=200&u3_tlen=150&u3_slen=300&u4_tlen=200&u4_slen=400&u5_tlen=250&u5_slen=500&pc_starts=4,7,10,13,16,19,22&pc_layouts=3u2u_2u1u-2u1u,3u2u_2u1u-2u1u,3u2u_2u1u-2u1u,3u2u_2u1u-2u1u,3u2u_2u1u-2u1u,3u2u_2u1u-2u1u,3u2u_2u1u-2u1u&display_show_logo=0&spaceid=792883968&mit=TV%20Media%20Slate

 

If you change the "list_id" valut, you should be able to grab all sorts of different stuff. Messing with the other values might yield some benefit too.

 

The "list_id" for Burning Love is buried in the the source HTML of the main series page.


YUI.namespace("Media").CONTENT_ID = "776ceaf7-5465-3510-ac37-68e62a53537b" 

 

 

 

Have fun :D

 

Above is some advice Mike was giving me on another post, but I wanted to start a separate post on the subject of JSON.

 

I am feeling a little like an idiot here, but I am having a hard time getting my head around JSON for channel development.

I get the basic concepts how the programming works.  But I am having trouble with how to find the data and pull it in my channel.

The best way I have found to figure this out is to pull up Goggle Chrome, go to the Network, and pull up all the Javascript coding to see if any are javascripts that have data stored in them (in field like 0,1,2) that have application/json in the header.

 

Then with Mike's example and help above, I figured out that you just need to find some JSON data on the site and just changed the content id to that of the show I am trying to access.  I was able to get the JSON data for Burning Love to come up by just changing the content id. Though I do not know if I need to change any of the other data after the id.  Also, the media id is available in each shows html page. (though I was not abe to get a response when I changed it to the Yahoo Screens originals page id)

 

But this is where I get confused. Though I get that this means I can call these JSON data items in my channel, using JSON parsing, how do I tell it to access those data items?

 

Most channels I have seen just seem to call the URL of the page that contains JSON data, but if I have to alter the id of JSON on that page to get this data, how would I call it? The individual show pages and the original shows page do not seem to call any json data.
 

I think I finally figured it out.  If I can find a json data file in the Network section, I use the URL of the raw JSON data file that I find for the page to parse the data.

Sounds like you've got the idea.

I am starting to finally. And you are right.  Once you find the JSON data, it is much easier to program the channel.

Got a couple questions on the topic of JSON.  First, if a data field is empty, will it still process and return the objects? For example lets say you have title, url, thumb and date that you are pulling from the JSON data and returning to corresponding video objects. What if one of your date fields in the JSON data is for example "date":"". Would that cause the channel program to kick the process out of the for loop it is in to gather data and not return any objects?

Also, how would you to set up an if else, where if JSON data exists, else try another method? I tried the code below, but kept getting errors. What was I doing wrong?

  data = JSON.ObjectFromURL(url)
  if data.has_key['items']:
     
  else:
    

Your code should work except that .has_key needs ('key_name') not ['key_name'].  Another option is a try-catch block:

try:
    
except: #if an error is thrown trying to complete < A >, then do < B >
    

A more pythonic way is to use if ... in ...

data = JSON.ObjectFromURL(url)

if ‘title’ in data:
    # do something
else:
    # do someting else

I ended up going with the try except, because I could not get the if else to work. But thanks, for the proper way to add the if else with JSON. It was one of those kinks I couldn't figure out and it was bothering me.  Now I know. Thanks again.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.