def list(type, extra=""):
if extra != "":
entity = "http://api.crunchbase.com/v/1/" + type + "/" + extra + ".js?api_key=" + key
data = json.load(urllib2.urlopen(entity))
else:
entity = "http://api.crunchbase.com/v/1/" + type + ".js?api_key=" + key
data = json.load(urllib2.urlopen(entity))
return data
函数列表在这里被专门调用:
x = colink
details = list(co, x)
特别是在 x 是“if_this_then_that”且 co 是“company”的情况下
当我在第二行查询(实体链接格式正确)时,代码在这一行中断。错误消息如下,JSON 文件中发生错误的行如下。通过 JSON API 获取数据时,我不确定如何处理 unicode 错误。任何有关如何解决此问题的建议将不胜感激。
Traceback (most recent call last):
File "crunch_API.py", line 95, in <module>
details = list(co, x)
File "crunch_API.py", line 34, in list
data = json.load(urllib2.urlopen(entity))
File "C:\Python27\lib\json\__init__.py", line 278, in load
**kw)
File "C:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Invalid control character at: line 24 column 89 (char 881)
"overview": "\u003Cp\u003EIFTTT 是一项服务,可让您通过一个简单的语句创建强大的连接:if this then that.\u003C/p\u003E", #### 错误发生的位置