python - 在 django 模板中的字典中迭代字典
问题描述
{
"0": {
"id": "20",
"user_id": "1865",
"amount": "100",
"currency_id": "153",
"content_ids": "17408",
"invoice_id": "72f5014243f8d",
"order_number": "387049404M2007243",
"gateway_response": "{\"TIMESTAMP\":\"2018-10-08T12:30:17Z\",\"CORRELATIONID\":\"72f5014243f8d\",\"ACK\":\"Success\",\"VERSION\":\"57.0\",\"BUILD\":\"46457558\",\"AMT\":\"100.00\",\"CURRENCYCODE\":\"USD\",\"AVSCODE\":\"Y\",\"CVV2MATCH\":\"S\",\"TRANSACTIONID\":\"387049404M2007243\"}",
"created_date": "2018-10-24 12:42:55",
"ordered_on": "Wed, Oct 24th '18",
"currency_code": "USD",
"currency_symbol": "$",
"content_details": {
"fid": "17408",
"id": "4f6b08955b1fc1049cc51869f36b1853",
"name": "Carol of the Bells SATB - arr. Jay Rouse",
"story": null,
"content_types_id": "6",
"app_id": "5",
"permalink": "carol-of-the-bells-satb-arr-jay-rouse"
},
"poster_url": "http://devstudio.cnedocent.com/img/No-Image-Vertical.png",
"seller_details": {
"email": "afixi.gayadhar@gmail.com",
"first_name": "Gayadhar khilar"
},
"price_details": {
"price": "100",
"price_id": "1",
"code": "USD",
"symbol": "$"
}
},
我想从上面的 json 响应中获取内容详细信息中的名称,但我无法迭代它。怎么做?
解决方案
import json
strJson = '''
<your JSON string>
'''
dictJson = json.loads(strJson)
# python 2.X
for key, value in dictJson.iteritems():
print (value['content_details']['name'])
# python 3.X
for key, value in dictJson.items():
print (value['content_details']['name'])
推荐阅读
- r - 获取数据框中的唯一因子值
- arrays - 如何检查schema.field.dataype是否是带有火花的scala中的字符串数组
- angular - 来自 API for Data Table Angular 的嵌套数组 json
- shiny - 基于pickerinput选择的闪亮更新表格内容
- javascript - 测试一个 redux 函数
- reactjs - 我是否正确使用了 useEffect 和取消订阅?
- php - 嗨,我正在尝试解析谷歌结果页面以提取所有 URL
- angular - 如何从以下本地 json 文件访问密钥?
- reactjs - 忽略 React App 中服务 index.html 文件中的特定 url
- python - 可点击的字形在散景上生成图