简体   繁体   English

将 json 字典转换为 python 中的数组

[英]convert json dict to array in python

I have data like and I would like to covert it to an array in python, this is the data and code I have tried below我有类似的数据,我想将其转换为 python 中的数组,这是我在下面尝试过的数据和代码

{
 "appUuid": "aaaa-bbbb-cccc",
 "SystemId": null,
 "city": "Lancaster",
 "state": "NY",
 "zipCode": "140",
 "field1": "others",
 "field2": "others"
}
{
 "appUuid": "bbbb-dddd-eeee",
 "SystemId": null,
 "city": "Alden ",
 "state": "NY",
 "zipCode": "140",
 "field1": "others",
 "field2": "others"
}

I would like to convert it to something like this我想把它转换成这样的东西

[{
 "appUuid": "aaaa-bbbb-cccc",
 "SystemId": null,
 "city": "Lancaster",
 "state": "NY",
 "zipCode": "140",
 "field1": "others",
 "field2": "others"
},
{
 "appUuid": "bbbb-dddd-eeee",
 "SystemId": null,
 "city": "Alden ",
 "state": "NY",
 "zipCode": "140",
 "field1": "others",
 "field2": "others"
}]

I tried我试过了

data1 = json.loads(data)
for item in data1:
  print(data1)

But is returning only one record multiple times, see output但是多次只返回一条记录,请参阅 output

{"appUuid": "aaaa-bbbb-cccc", "SystemId": null, "city": "Lancaster", "state": "NY", "zipCode": "140", "field1": "others","field2": "others"}
{"appUuid": "aaaa-bbbb-cccc", "SystemId": null, "city": "Lancaster", "state": "NY", "zipCode": "140", "field1": "others","field2": "others"}
{"appUuid": "aaaa-bbbb-cccc", "SystemId": null, "city": "Lancaster", "state": "NY", "zipCode": "140", "field1": "others","field2": "others"}

Please help, thanks请帮忙,谢谢

You should just print like this.你应该像这样打印。 The data you received is already as you wanted.您收到的数据已经如您所愿。

data1 = json.loads(data)
for item in data1:
    print(item)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM