如何使用python解析键值数据

2024-03-29 11:44:52 发布

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

我想用python解析rest响应的值

我尝试将数据作为键值对进行拉取,但它不喜欢。你知道吗

我想解析值字段数据

"""[{'name': u'id', 'value': u'000000471687 \n000000471688 \n000000471689 \n'}]"""

实际需要的输出是:

tasks = 000000471687, 000000471688, 000000471689

Tags: 数据namerestidvalue键值tasksn000000471688
1条回答
网友
1楼 · 发布于 2024-03-29 11:44:52

您可以通过以下方式进行:

data = """[{'name': u'id', 'value': u'000000471687 \n000000471688 \n000000471689 \n'}]"""

data=eval(data.replace("\n'","'").replace('\n',','))

tasks = ','.join([ str(s).strip() for i in data for s in i['value'].split(',')])

相关问题 更多 >