在我的控制器中,我得到一个 json 字符串(调用c.order_history
它看起来像:
[
{
"status": [
{
"status": "created",
"timestamp": "2012-04-06 00:14:10"
},
{
"status": "authed",
"timestamp": "2012-04-06 00:14:17"
}
],
"product_info": [
{
"id": 3,
"quantity": 1,
"created": "2012-04-06 00:14:10",
"image_id": 13341
},
{
"id": 2,
"quantity": 1,
"created": "2012-04-06 00:14:10",
"image_id": 13323
},
{
"id": 1,
"quantity": 1,
"created": "2012-04-06 00:14:10",
"image_id": 13322
}
],
"shipping_charge": "0.00",
"order_number": "0723094747433",
"shipping_address": {
"country_code": null,
"extended_address": "Unit Z",
"locality": "Las Vagas",
"company": null,
"phone": null,
"postal_code": "31415",
"full_name": "Boris Karloff",
"nickname": null,
"region": "NV",
"street_address": "123 Random Way"
},
"subtotal": "59.00"
}
]
我通过它json.loads(order_history)
把它变成一个字典,然后尝试提取每个键,这样我就可以得到它们中的后续键/值,例如:
c.product_info = [{'product_info' : product_info} for product_info in c.order_history]
它输出整个 json 字符串,但它product_info
现在刚刚命名。有人可以引导我朝着正确的方向前进,了解我如何访问说、timestamp
价值product_info[0]['image_id']
和shipping_address
价值等吗?