Python 如何将json从页面源代码解码到字典?

Python 如何将json从页面源代码解码到字典?,python,json,python-3.x,string,dictionary,Python,Json,Python 3.x,String,Dictionary,以下是页面源代码中的一些JSON: match_info = JSON.parse('\x7B\x22id\x22\x3A\x2211768\x22,\x22fid\x22\x3A\x221376025\x22,\x22h\x22\x3A\x2272\x22,\x22a\x22\x3A\x2279\x22,\x22date\x22\x3A\x222019\x2D11\x2D23\x2015\x3A00\x3A00\x22,\x22league_id\x22\x3A\x221\x22,\x22s

以下是页面源代码中的一些JSON:

match_info  = JSON.parse('\x7B\x22id\x22\x3A\x2211768\x22,\x22fid\x22\x3A\x221376025\x22,\x22h\x22\x3A\x2272\x22,\x22a\x22\x3A\x2279\x22,\x22date\x22\x3A\x222019\x2D11\x2D23\x2015\x3A00\x3A00\x22,\x22league_id\x22\x3A\x221\x22,\x22season\x22\x3A\x222019\x22,\x22h_goals\x22\x3A\x220\x22,\x22a_goals\x22\x3A\x222\x22,\x22team_h\x22\x3A\x22Everton\x22,\x22team_a\x22\x3A\x22Norwich\x22,\x22h_xg\x22\x3A\x220.812693\x22,\x22a_xg\x22\x3A\x221.80849\x22,\x22h_w\x22\x3A\x220.1424\x22,\x22h_d\x22\x3A\x220.2108\x22,\x22h_l\x22\x3A\x220.6468\x22,\x22league\x22\x3A\x22EPL\x22,\x22h_shot\x22\x3A\x2218\x22,\x22a_shot\x22\x3A\x2213\x22,\x22h_shotOnTarget\x22\x3A\x227\x22,\x22a_shotOnTarget\x22\x3A\x225\x22,\x22h_deep\x22\x3A\x2215\x22,\x22a_deep\x22\x3A\x224\x22,\x22a_ppda\x22\x3A\x228.2174\x22,\x22h_ppda\x22\x3A\x225.9565\x22\x7D');
尝试使用
json.loads()
方法将其转换为字典时,出现以下错误:

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    json.loads(shots)
  File "C:\Users\turnc\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\turnc\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\turnc\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
加载(快照)
文件“C:\Users\turnc\AppData\Local\Programs\Python\Python37-32\lib\json\\ u_init\u_.py”,第348行,在loads中
返回\u默认\u解码器。解码
文件“C:\Users\turnc\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py”,第337行,在decode中
obj,end=self.raw\u decode(s,idx=\u w(s,0.end())
文件“C:\Users\turnc\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py”,第355行,原始解码
从None引发JSONDecodeError(“预期值”,s,err.value)
json.decoder.JSONDecodeError:预期值:第1行第1列(字符0)
使用双引号也没有帮助


如何将此字符串转换为Python中的字典?

尝试此操作-使用以下命令将其转换为类型对象:

或者使用
结果
变量中的字符串:

>>> json.loads(bytes(result, 'utf-8'))
{'id': '11768',
 'fid': '1376025',
 'h': '72',
 'a': '79',
 'date': '2019-11-23 15:00:00',
 'league_id': '1',
 'season': '2019',
 'h_goals': '0',
 'a_goals': '2',
 'team_h': 'Everton',
 'team_a': 'Norwich',
 'h_xg': '0.812693',
 'a_xg': '1.80849',
 'h_w': '0.1424',
 'h_d': '0.2108',
 'h_l': '0.6468',
 'league': 'EPL',
 'h_shot': '18',
 'a_shot': '13',
 'h_shotOnTarget': '7',
 'a_shotOnTarget': '5',
 'h_deep': '15',
 'a_deep': '4',
 'a_ppda': '8.2174',
 'h_ppda': '5.9565'}

它确实可以工作,但是我怎样才能将json作为变量而不是字符串文本来传递呢?
>>> json.loads(bytes(result, 'utf-8'))
{'id': '11768',
 'fid': '1376025',
 'h': '72',
 'a': '79',
 'date': '2019-11-23 15:00:00',
 'league_id': '1',
 'season': '2019',
 'h_goals': '0',
 'a_goals': '2',
 'team_h': 'Everton',
 'team_a': 'Norwich',
 'h_xg': '0.812693',
 'a_xg': '1.80849',
 'h_w': '0.1424',
 'h_d': '0.2108',
 'h_l': '0.6468',
 'league': 'EPL',
 'h_shot': '18',
 'a_shot': '13',
 'h_shotOnTarget': '7',
 'a_shotOnTarget': '5',
 'h_deep': '15',
 'a_deep': '4',
 'a_ppda': '8.2174',
 'h_ppda': '5.9565'}