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为“公司”的实例上
当我在第二行查询时(实体链接格式正确),代码在此行上出现故障。错误消息位于下方,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)
“概述”:“\ u003Cp \ u003EIFTTT是一项服务,它允许您使用一个简单的语句创建强大的连接:如果这样。\ u003C / p \ u003E”,####发生错误的位置