从此输出刮取值

问题描述 投票:0回答:1

晚上好,

我想从此输出中刮取“值”:

{
  "checkout":
  {
    "completed_at": null,
    "created_at": "2020-02-27T00:32:40+01:00",
    "currency":"EUR",
    "presentment_currency":"EUR",
    "customer_id":2929596792912,
    "customer_locale":"de"
    ...

依此类推。...

我的尝试:

import json
Json = json.loads(info.text)
currency= Json1.get("currency")
print(currency

但是打印答案时我只得到None

python json search scrape
1个回答
1
投票

使用json库解析输入后,您将拥有一个python字典。

get("currency")返回None的原因是,键currency在字典的顶层不存在。

如果您尝试

currency = Json.get("checkout").get("currency")

您应该获得值EUR

© www.soinside.com 2019 - 2024. All rights reserved.