【发布时间】:2014-02-13 09:51:08
【问题描述】:
我有一个带有以下示例 json 条目的 json 文件:
{
"title": "Test prod",
"leafPage": true,
"type": "product",
"product": {
"title": "test product",
"offerPrice": "$19.95",
"offerPriceDetails": {
"amount": 19.95,
"text": "$19.95",
"symbol": "$"
},
"media": [
{
"link": "http://www.test.com/cool.jpg",
"primary": true,
"type": "image",
"xpath": "/html[1]/body[1]/div[1]/div[3]/div[2]/div[1]/div[1]/div[1]/div[1]/a[1]/img[1]"
}
],
"availability": true
},
"human_language": "en",
"url": "http://www.test.com"
}
当我使用时,我可以通过 python 脚本将它完美地发布到我的测试服务器:
"text": entry.get("title"),
"url": entry.get("url"),
"type": entry.get("type"),
但是我无法获取以下嵌套项来上传值,如何构建 python json 调用以获取嵌套的 python json 条目?
我尝试了以下但没有成功,我需要将它作为 .get ,因为 json 文件中当前有不同的字段,并且在没有 .get 调用的情况下会出错。
"Amount": entry.get("product"("offerPrice"))
非常感谢任何有关如何构建嵌套 json 条目的帮助。
【问题讨论】: