parsing json data

This is the place for queries that don't fit in any of the other categories.

parsing json data

Postby patapat » Mon Apr 22, 2013 8:37 pm

http://data.sportsillustrated.cnn.com/j ... yplay.json

I'm having difficulty getting this data to load and I'm not exactly sure what the issue is.

Simply doing this:

import json, urllib

j = urllib.urlopen("http://data.sportsillustrated.cnn.com/jsonp/basketball/nba/gameflash/2013/04/17/32956_playbyplay.json").read()
js = json.loads(j)

doesn't work.

I'm not sure if this callbackWrapper is affecting the structure of the data or if there is simply too much data to load.

Thank you for any and all help!
patapat
 
Posts: 2
Joined: Mon Apr 22, 2013 8:31 pm

Re: parsing json data

Postby stranac » Mon Apr 22, 2013 8:46 pm

Read this for future reference on how to ask for help properly.

But yes, the 'callbackWrapper' thing makes the data not valid json.
You'll need to get rid of that part, and then use json.loads().
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm

Re: parsing json data

Postby snippsat » Mon Apr 22, 2013 9:33 pm

Try it like this.
Code: Select all
import json, urllib

j = urllib.urlopen("http://data.sportsillustrated.cnn.com/jsonp/basketball/nba/gameflash/2013/04/17/32956_playbyplay.json").read()[16:][:-2]
js = json.loads(j)
print js
User avatar
snippsat
 
Posts: 269
Joined: Thu Feb 21, 2013 12:04 am

Re: parsing json data

Postby stranac » Mon Apr 22, 2013 9:43 pm

snippsat wrote:
Code: Select all
[16:][:-2]

should really be a single slice:
Code: Select all
[16:-2]
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm

Re: parsing json data

Postby patapat » Mon Apr 22, 2013 9:56 pm

My apologies stranac, I should've been more thorough with my post, thanks for the help though.

snippsat, thanks for the tip! I'll work with that when I get the chance.

Thanks for the timely, helpful responses guys!
patapat
 
Posts: 2
Joined: Mon Apr 22, 2013 8:31 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 4 guests