繁体   English   中英

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

[英]How to get a specific value in a json string in python 3.6

我试图在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":"74d57a754855410c90b3d51bc99b8beb"}}"我只想打印以下值: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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM