Odd json encoding erro

Intchanter / Daniel Fackrell unlearned at gmail.com
Tue Dec 15 17:24:24 EST 2009


On Dec 15, 3:03 pm, Wells <thewellsoli... at gmail.com> wrote:
> I get this exception when decoding a certain JSON string:
>
> 'ascii' codec can't encode character u'\u2019' in position 8: ordinal
> not in range(128)
>
> The JSON data in question:
>
> http://mlb.com/lookup/json/named.player_info.bam?sport_code=%27mlb%27...
>
> It's in the 'high_school' key. Is there some string function I can run
> on the information before I decode it to avoid this?

In my test using this same data, I did not get such an error.  Here's
my code:

data = '{"player_info": {"queryResults": { "row": { "active_sw": "Y",
"bats": "R", "birth_city": "Baltimore", "birth_country": "USA",
"birth_date": "1987-08-31T00:00:00", "birth_state": "MD", "college":
"", "death_city": "", "death_country": "", "death_date": "",
"death_state": "", "end_date": "", "file_code": "sf", "gender": "M",
"height_feet": "6", "height_inches": "1", "high_school": "St. Paul
\u2019s School For Boys (MN) HS", "jersey_number": "",
"name_display_first_last": "Steve Johnson",
"name_display_first_last_html": "Steve Johnson",
"name_display_last_first": "Johnson, Steve",
"name_display_last_first_html": "Johnson, Steve",
"name_display_roster": "Johnson, S", "name_display_roster_html":
"Johnson, S", "name_first": "Steven", "name_full": "Johnson, Steve",
"name_last": "Johnson", "name_matrilineal": "", "name_middle":
"David", "name_nick": "", "name_prefix": "", "name_title": "",
"name_use": "Steve", "player_id": "489002", "primary_position": "1",
"primary_position_txt": "P", "primary_sport_code": "",
"pro_debut_date": "", "start_date": "2009-12-10T00:00:00", "status":
"Active", "status_code": "A", "status_date": "2009-12-10T00:00:00",
"team_abbrev": "SF", "team_code": "sfn", "team_id": "137",
"team_name": "San Francisco Giants", "throws": "R", "weight": "200" },
"totalSize": "1" }}}'

import json

print json.loads(data)

(I'm running 2.6.4 on Mac OS X)

Intchanter
Daniel Fackrell



More information about the Python-list mailing list