我有一个JSON,看起来像这样:
"payment_methods": [{
"payment_type": "CC",
"cardSubType": "AX",
"card_number": "377777684182882",
"expiration_month": "01",
"expiration_year": "2018",
"security_code": "",
"cvv2": "",
"name": {
"first_name": "John",
"last_name": "Smith"
},
"billing_address": {
"country": "United States",
"address_line1": "666 SUNSET BLVD",
"address_line2": null,
"city": "Anaheim",
"state": "California",
"zip_code": "92808",
"phone": "0123456789"
},
"payment_amount": "",
"payment_percentage": ""
}]
需要做的是将billing_address
保存到一个变量中,以便以后使用该dict中的值。
billing_address in payment_methods
行得通吗?你知道吗
有没有更好的方法?你知道吗
所以你想获得billing\u address属性?你知道吗
您有一个JSON字符串,所以将其解析到Python字典中。(几乎有效的)字符串表示一个字典,但它需要包含在} 这样做:
{
和}
中。假设json字符串是从其他API返回的,可以使用^{现在可以使用^{} 模块将字符串解析到字典中,并通过访问字典中相应的键和列表索引来获取帐单地址的详细信息。假设您只需要(可能有许多)付款方式列表中第一种付款方式的帐单详细信息:
我会把这些分成两本字典。带有地址的第二个字典将存储在变量
billing_address
它看起来是这样的:
相关问题 更多 >
编程相关推荐