Python/Json:期望属性名称用双引号引起来 [英] Python/Json:Expecting property name enclosed in double quotes

查看:205
本文介绍了Python/Json:期望属性名称用双引号引起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找一种在Python中加载JSON对象的好方法. 我发送此json数据:

I've been trying to figure out a good way to load JSON objects in Python. I send this json data:

{'http://example.org/about': {'http://purl.org/dc/terms/title': [{'type': 'literal', 'value': "Anna's Homepage"}]}}

到后端,它将以字符串形式接收,然后我使用json.loads(data)对其进行了解析.

to the backend where it will be received as a string then I used json.loads(data) to parse it.

但是每次我遇到相同的异常:

But each time I got the same exception :

ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

我用Google搜索了它,但除了此解决方案json.loads(json.dumps(data))似乎没有任何用处,对于我个人而言,它似乎效率不高,因为它可以接受任何类型的数据,甚至包括非json格式的数据.

I googled it but nothing seems to work besides this solution json.loads(json.dumps(data)) which personally seems for me not that efficient since it accept any kind of data even the ones that are not in json format.

任何建议将不胜感激.

推荐答案

此:

{'http://example.org/about': {'http://purl.org/dc/terms/title': [{'type': 'literal', 'value': "Anna's Homepage"}]}}

不是JSON.
这个:

is not JSON.
This:

{"http://example.org/about": {"http://purl.org/dc/terms/title": [{"type": "literal", "value": "Anna's Homepage"}]}}

是JSON.

这篇关于Python/Json:期望属性名称用双引号引起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆