比如说给一个json数据:
[
{
"Name": "A1",
"No": "3111",
"createDate": "9999/12/31 00:00:00",
"lastUpdDate": "9999/12/31 00:00:00"
},
{
"Name": "B2",
"No": "2222",
"createDate": "9999/12/31 00:00:00",
"lastUpdDate": "9999/12/31 00:00:00"
},
{
"Name": "C3",
"No": "1444",
"createDate": "9999/12/31 00:00:00",
"lastUpdDate": "9999/12/31 00:00:00"
},
{
"Name": "C4",
"No": "0542",
"createDate": "9999/12/31 00:00:00",
"lastUpdDate": "9999/12/31 00:00:00"
}
]
我想要No为"0542"的一条记录:
{
"Name": "C4",
"No": "0542",
"createDate": "9999/12/31 00:00:00",
"lastUpdDate": "9999/12/31 00:00:00"
}
如果用python3应该怎么实现?
我网上搜索了类似代码
比如 data = list(filter(lambda d: d['No'] == "0542", jsondata))
改来改去,总是报各种类型错误,抓狂了……所以请教下大家,应该怎么写,谢谢!
假设有 json string 如下:
代码:
结果:
我回答过的问题: Python-QA