在使用 Python 的 GAE 上,我使用 urlfetch 从 Flickr 获取 json 字符串。当我尝试在生产服务器上使用 json.loads 加载该字符串时,抛出异常“raised ValueError(Unpaired high surrogate)”。
当我尝试在开发控制台中 json.loads 字符串时,它会按预期加载到字典中(见下文)。我已经使用相同的代码从 Flickr 成功加载了其他几个 json 字符串。下面的 json 字符串有些内容仅在生产服务器上引发 ValueError 异常。
import json
s = """{"photo":{"id":"191019103", "secret":"d7a8bb95bc", "server":"72", "farm":1, "dateuploaded":"1153079847", "isfavorite":0, "license":"1", "safety_level":"0", "rotation":0, "originalsecret":"d7a8bb95bc", "originalformat":"jpg", "owner":{"nsid":"13968020@N00", "username":"\ud800dc80 jgraham", "realname":"", "location":"", "iconserver":"38", "iconfarm":1}, "title":{"_content":"By the Year 2000 All Our Food Will be in the Form of Tiny Pills"}, "description":{"_content":""}, "visibility":{"ispublic":1, "isfriend":0, "isfamily":0}, "dates":{"posted":"1153079847", "taken":"2006-07-15 14:31:16", "takengranularity":"0", "lastupdate":"1282690106"}, "views":"984", "editability":{"cancomment":0, "canaddmeta":0}, "publiceditability":{"cancomment":1, "canaddmeta":0}, "usage":{"candownload":1, "canblog":0, "canprint":0, "canshare":1}, "comments":{"_content":"18"}, "notes":{"note":[]}, "people":{"haspeople":0}, "tags":{"tag":[{"id":"1207251-191019103-2909", "author":"13968020@N00", "raw":"Birmingham", "_content":"birmingham", "machine_tag":0}, {"id":"1207251-191019103-77552", "author":"13968020@N00", "raw":"Bullring", "_content":"bullring", "machine_tag":0}, {"id":"1207251-191019103-463", "author":"13968020@N00", "raw":"Abstract", "_content":"abstract", "machine_tag":0}, {"id":"1207251-191019103-1174", "author":"13968020@N00", "raw":"Architecture", "_content":"architecture", "machine_tag":0}, {"id":"1207251-191019103-141", "author":"13968020@N00", "raw":"Blue", "_content":"blue", "machine_tag":0}, {"id":"1207251-191019103-2194948", "author":"13968020@N00", "raw":"i500", "_content":"i500", "machine_tag":0}, {"id":"1207251-191019103-11820", "author":"13968020@N00", "raw":"Explore", "_content":"explore", "machine_tag":0}, {"id":"1207251-191019103-3254511", "author":"13968020@N00", "raw":"utata_feature", "_content":"utatafeature", "machine_tag":0}]}, "urls":{"url":[{"type":"photopage", "_content":"http:\/\/www.flickr.com\/photos\/jgraham\/191019103\/"}]}, "media":"photo"}, "stat":"ok"}"""
print json.loads(s) #prints dict