有什么方法可以使simplejson变得不那么严格? [英] Is there any way to make simplejson less strict?

查看:96
本文介绍了有什么方法可以使simplejson变得不那么严格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣让simplejson.loads()成功解析以下内容:

I'm interested in having simplejson.loads() successfully parse the following:

{foo:3}

它抛出一个JSONDecodeError,上面写着期望属性名称",但实际上是在说我需要在属性名称周围用双引号引起来".这对于我的用例来说很烦人,我宁愿选择一个不太严格的行为.我已经阅读了文档,但是除了制作自己的解码器类之外,我看不到任何明显的东西可以改变这种行为.

It throws a JSONDecodeError saying "expecting property name" but in reality it's saying "I require double quotes around my property names". This is annoying for my use case, and I'd prefer a less strict behavior. I've read the docs, but beyond making my own decoder class, I don't see anything obvious that changes this behavior.

推荐答案

您可以使用YAML(> = 1.2),因为它是JSON的超集,您可以执行以下操作:

You can use YAML (>=1.2)as it is a superset of JSON, you can do:

>>> import yaml
>>> s = '{foo: 8}'
>>> yaml.load(s)
{'foo': 8}

这篇关于有什么方法可以使simplejson变得不那么严格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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