Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python 3.6中获取json字符串中的特定值_Python_Json_Python 3.x - Fatal编程技术网

如何在python 3.6中获取json字符串中的特定值

如何在python 3.6中获取json字符串中的特定值,python,json,python-3.x,Python,Json,Python 3.x,我试图在一个json字符串中获得一个特定的值,但我不知道如何准确地实现它。我不想将其转换为字符串,然后剥离/替换不需要的部分,因为那样我就无法获得其他值。我目前的代码是: username = "Dextication" url = f"https://minecraft-statistic.net/api/player/info/{username}/" response = requests.get(url) json_data = json.loads(re

我试图在一个json字符串中获得一个特定的值,但我不知道如何准确地实现它。我不想将其转换为字符串,然后剥离/替换不需要的部分,因为那样我就无法获得其他值。我目前的代码是:

    username = "Dextication"
    url = f"https://minecraft-statistic.net/api/player/info/{username}/"
    response = requests.get(url)
    json_data = json.loads(response.text)
    print(json_data)
编辑: 当我运行这个程序时,
json.data=“{”status:“ok”,“data:{”online:“0”,“total_time_play:”46990,“last_play:”1513960562,“license:”1,“name:“Dextication”,“uuid:”74D57A7548555410C90B3D51BC99B8BEB“}”
我只想打印值:46990

请尝试下面的代码

import json, requests

username = "Dextication"
url = f"https://minecraft-statistic.net/api/player/info/{username}/"
response = requests.get(url)
json_data = json.loads(response.text)
result = json_data['data']['total_time_play']
print (result)

不太清楚你在问什么。您只需要json响应中的值吗?如果是,只需通过他们的钥匙访问即可
json.loads()
返回字典。然后,您可以使用dict的所有方法。