我应该如何从json字符串的数组对象下面解析“text”值?

2024-04-29 09:38:05 发布

您现在位置:Python中文网/ 问答频道 /正文

[“{\”贡献者\“:null,\”截断\“:false,\”文本\“:\”RT@itisprashanth:关于贾利卡图的所有请愿书将于明天由最高法院审理。明天将是所有年轻人的节日


Tags: 文本falsenullrt年轻人请愿书itisprashanth利卡
2条回答

使用json模块将字符串转换为json对象。你知道吗

例如:

import json
h = ["{\"contributors\": null, \"truncated\": false, \"text\": \"RT @itisprashanth: All petitions regarding #jallikattu to be heard by Supreme Court tomorrow. Tomorrow will be the D-Day for all the Youth\u2026\"}"]
for i in h:
    v = json.loads(i)
    print v["text"]

输出:

RT @itisprashanth: All petitions regarding #jallikattu to be heard by Supreme Court tomorrow. Tomorrow will be the D-Day for all the Youth…

只需将字符串(给定数组的第一个元素)解析为JSON对象,并获取其文本值。你知道吗

import json
arr = ["{"contributors": null, "truncated": false, "text": "RT @itisprashanth: All petitions regarding #jallikattu to be heard by Supreme Court tomorrow. Tomorrow will be the D-Day for all the Youth\u2026"}"]
print(json.loads(arr[0])["text"])
# "RT @itisprashanth: All petitions regarding #jallikattu to be heard by Supreme Court tomorrow. Tomorrow will be the D-Day for all the Youth\u2026"

相关问题 更多 >