API/JSON 值错误
API/JSON Value Error
当我输入 url:
时,我一直在尝试使用具有以下响应的 API
{
"resource": "playerdashptshotlog",
"parameters": {
"LeagueID": "00",
"Season": "2014-15",
"SeasonType": "Regular Season",
"PlayerID": 202066,
"TeamID": 0,
"Outcome": null,
"Location": null,
"Month": 0,
"SeasonSegment": null,
"DateFrom": null,
"DateTo": null,
"OpponentTeamID": 0,
"VsConference": null,
"VsDivision": null,
"GameSegment": null,
"Period": 0,
"LastNGames": 0
},
"resultSets": [
我的代码如下:
import json, requests
github_url = 'http:dsds
parsed_input = json.loads(github_url)
print (parameters.keys())
print (parameters['LeagueID']['Season'])
我在使用 Python34 时收到错误消息:
Traceback (most recent call last): File "C:\Python34\Scripts\NBA
API-JSON.py", line 27, in
parsed_input = json.loads(github_url) File "C:\Python34\lib\json__init__.py", line 318, in loads
return _default_decoder.decode(s) File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None ValueError: Expecting value: line 1 column 1 (char 0)
当我 运行 它在 Python27 上时,我得到这个错误:
Traceback (most recent call last): File "C:\Python27\Scripts\NBA
API-JSON.py", line 27, in
parsed_input = json.loads(github_url) File "C:\Python27\lib\json__init__.py", line 338, 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 384, in raw_decode
raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded
我想弄清楚我做错了什么。我尝试使用在以下位置找到的问题的示例答案:
Parsing Multidimensional JSON Array
您好像忘记获取数据了。尝试:
github_url = 'http://whatever'
r = requests.get(github_url)
if r.status_code == 200:
parsed_input = json.loads(r.text)
请求还可以为您解析JSON:
parsed_input = r.json()
当我输入 url:
时,我一直在尝试使用具有以下响应的 API{
"resource": "playerdashptshotlog",
"parameters": {
"LeagueID": "00",
"Season": "2014-15",
"SeasonType": "Regular Season",
"PlayerID": 202066,
"TeamID": 0,
"Outcome": null,
"Location": null,
"Month": 0,
"SeasonSegment": null,
"DateFrom": null,
"DateTo": null,
"OpponentTeamID": 0,
"VsConference": null,
"VsDivision": null,
"GameSegment": null,
"Period": 0,
"LastNGames": 0
},
"resultSets": [
我的代码如下:
import json, requests
github_url = 'http:dsds
parsed_input = json.loads(github_url)
print (parameters.keys())
print (parameters['LeagueID']['Season'])
我在使用 Python34 时收到错误消息:
Traceback (most recent call last): File "C:\Python34\Scripts\NBA API-JSON.py", line 27, in parsed_input = json.loads(github_url) File "C:\Python34\lib\json__init__.py", line 318, in loads return _default_decoder.decode(s) File "C:\Python34\lib\json\decoder.py", line 343, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode raise ValueError(errmsg("Expecting value", s, err.value)) from None ValueError: Expecting value: line 1 column 1 (char 0)
当我 运行 它在 Python27 上时,我得到这个错误:
Traceback (most recent call last): File "C:\Python27\Scripts\NBA API-JSON.py", line 27, in parsed_input = json.loads(github_url) File "C:\Python27\lib\json__init__.py", line 338, 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 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded
我想弄清楚我做错了什么。我尝试使用在以下位置找到的问题的示例答案:
Parsing Multidimensional JSON Array
您好像忘记获取数据了。尝试:
github_url = 'http://whatever'
r = requests.get(github_url)
if r.status_code == 200:
parsed_input = json.loads(r.text)
请求还可以为您解析JSON:
parsed_input = r.json()