API/JSON值错误

API/JSON值错误,json,decode,Json,Decode,当我键入url时,我一直尝试使用具有以下响应的API: { "resource": "playerdashptshotlog", "parameters": { "LeagueID": "00", "Season": "2014-15", "SeasonType": "Regular Season", "PlayerID": 202066, "TeamID": 0, "Outcome"

当我键入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时,我发现一个错误:

回溯(最近一次调用):文件“C:\Python34\Scripts\NBA API-JSON.py”,第27行 已解析的输入=json.loads(github\uURL)文件“C:\Python34\lib\json\uuuuuu init\uuuuuuu.py”,第318行,在loads中 返回解码中第343行的默认解码器.decode文件“C:\Python34\lib\json\decoder.py” obj,end=self.raw_decode(s,idx=_w(s,0.end())文件“C:\Python34\lib\json\decoder.py”,第361行,在raw_decode中 从None ValueError引发ValueError(errmsg(“期望值”,s,err.value))错误:期望值:第1行第1列(字符0)

当我在Python27上运行它时,会出现以下错误:

回溯(最近一次调用):文件“C:\Python27\Scripts\NBA API-JSON.py”,第27行 已解析的输入=json.loads(github\uURL)文件“C:\Python27\lib\json\uuuuuu init\uuuuuu.py”,第338行,在loads中 返回解码中第366行的默认解码器.decode文件“C:\Python27\lib\json\decoder.py” obj,end=self.raw_decode(s,idx=_w(s,0.end())文件“C:\Python27\lib\json\decoder.py”,第384行,raw_decode raise VALUERROR(“无法解码JSON对象”)VALUERROR:无法解码JSON对象

我在想我做错了什么。我尝试使用在以下位置找到的问题的示例答案:


看起来您忘记提取数据了。尝试:

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()

您是否没有复制所有响应,因为您粘贴的内容不是有效的JSON,它以一个open
[
大约有60页,我怎么能只打印某些字段,例如:TeamID、PlayerID等?这样以后我就可以像处理表格格式一样处理这些值。@RossJohnson我认为这与你的问题无关。我相信这个答案回答了你的问题。如果你认为是这样,那么最好向上投票/acc接受它。我建议为此创建另一个问题,并提供更多详细信息。json.loads()返回一个常规python dict或list,具体取决于输入json。在您的示例中,执行解析的_input['parameters']['TeamID']等等。