我有这个JSON,当将其输入在线JSON格式器网站时,它表示JSON数据不准确。
{
"Hospitals":[
{
"name":"Centre"
"url":"www.example.com"
},
{
"name":"jdbcd"
"url":"www.example.net"
}
]
}
我知道正确的JSON数据是通过在名称属性的末尾添加逗号
{
"Hospitals":[
{
"name":"Centre",
"url":"www.example.com"
},
{
"name":"jdbcd",
"url":"www.example.net"
}
]
}
但实际上,我有大量的数据要格式化。我该如何以编程方式执行此操作(因为pythonjson.load(file.json)
给出了错误)或任何在线资源(我检查了Google排名靠前的结果,但均无效果)
有一些json的超集,例如hjson,这些超集的严格程度较低。我认为hjson将为您工作:
>>> import hjson
>>> hjson.loads(""" {
"Hospitals":[
{
"name":"Centre"
"url":"www.example.com"
},
{
"name":"jdbcd"
"url":"www.example.net"
}
]
}""")
OrderedDict([('Hospitals', [OrderedDict([('name', 'Centre'), ('url', 'www.example.com')]), OrderedDict([('name', 'jdbcd'), ('url', 'www.example.net')])])])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句