我正在使用 Google 的 Python 库。 我希望能够使用 simplejson 库。
但是,即使是他们的示例 未在 JSONLint 中验证:
{cols:
[{id:'name',label:'Name',type:'string'},
{id:'salary',label:'Salary',type:'number'},
{id:'full_time',label:'Full Time Employee',type:'boolean'}],
rows:
[{c:[{v:'Jim'},{v:800,f:'$800'},{v:false}]},
{c:[{v:'Bob'},{v:7000,f:'$7,000'},{v:true}]},
{c:[{v:'Mike'},{v:10000,f:'$10,000'},{v:true}]},
{c:[{v:'Alice'},{v:12500,f:'$12,500'},{v:true}]}]}
如何调整 simplejson 'loads' 函数以导入上述 JSON 内容? 我认为主要问题是对象键不是字符串。
我宁愿不编写正则表达式来将键转换为字符串,因为我认为这样的代码维护起来很烦人。
当我尝试使用 simplejson 将上述 JSON 导入 Python 时,当前收到“期望属性名称:第 1 行第 1 列(字符 1)”错误。
I am implementing a Google data source using their Python library. I would like the response from the library to be able to be imported in another Python script using the simplejson library.
However, even their example doesn't validate in JSONLint:
{cols:
[{id:'name',label:'Name',type:'string'},
{id:'salary',label:'Salary',type:'number'},
{id:'full_time',label:'Full Time Employee',type:'boolean'}],
rows:
[{c:[{v:'Jim'},{v:800,f:'$800'},{v:false}]},
{c:[{v:'Bob'},{v:7000,f:'$7,000'},{v:true}]},
{c:[{v:'Mike'},{v:10000,f:'$10,000'},{v:true}]},
{c:[{v:'Alice'},{v:12500,f:'$12,500'},{v:true}]}]}
How do I tweak the simplejson 'loads' function to import the above JSON content? I think the main problem is that the object keys are not strings.
I would rather not write a regular expression to convert the keys to strings since I think such code would be annoying to maintain.
I am currently getting an "Expecting property name: line 1 column 1 (char 1)" error when trying to import the above JSON into Python with simplejson.
发布评论
评论(1)
如果没有字符串键,它被认为是无效的 JSON。
必须是:
根据 Google 数据源页面,他们返回无效的 JSON。 他们没有具体说明,但他们的所有示例都缺少按键上的引号。
以下是 Python 的 JSON 处理器 的相当完整的列表,其中详细介绍了它们的格式支持,以及如何。 大多数不支持非字符串键,但似乎 demjson 会转换它。
It is considered to be invalid JSON without the string keys.
must be:
According to the Google Data Source page, they're returning invalid JSON. They don't specifically say it, but all their examples lack quotes on the keys.
Here is a fairly complete list of JSON processors for Python which goes into detail about what formats they support, and how well. Most don't support non-string keys, but it appears that demjson will convert it.