[英]Python code to read inner json value of an object
我有两个 json 我想加入两个 json 的内部值。 文本 + 内部数据中第一个 object 的文本 例如: "get an appointment with academic advisor"
"appointment with my academic advisor"
[
{
"id": "dadb4ddb-43d4-420f-aeb5-95ccf1479c51",
"data": [
{
"text": "get an appointment with ",
"userDefined": false
},
{
"text": "academic advisor",
"meta": "@sys.ignore",
"userDefined": false
}
],
"isTemplate": false,
"count": 0,
"updated": 0
},
{
"id": "d49948fe-3070-44b9-8756-3662ca041a58",
"data": [
{
"text": "appointment with ",
"userDefined": false
},
{
"text": "my advisor",
"meta": "@sys.ignore",
"userDefined": false
}
],
"isTemplate": false,
"count": 0,
"updated": 0
},
{
"id": "74447714-d6d8-432d-b7db-4c0505d31b33",
"data": [
{
"text": "set up appointment with ",
"userDefined": false
},
{
"text": "academic advisor",
"meta": "@sys.ignore",
"userDefined": false
}
],
"isTemplate": false,
"count": 0,
"updated": 0
},
{
"id": "e4dee863-2f97-496f-b9e6-cf0ed80da0d6",
"data": [
{
"text": "How can I set up an appointment with my academic advisor",
"userDefined": false
}
],
"isTemplate": false,
"count": 0,
"updated": 0
}
]
尝试这个:
import json
data = json.load(open('xxx.json'))
for d in data:
print(' ' .join([item['text'] for item in d['data']]))
Output:
get an appointment with academic advisor
appointment with my advisor
set up appointment with academic advisor
How can I set up an appointment with my academic advisor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.