Google数据源JSON无效吗? [英] Is Google data source JSON not valid?

查看:132
本文介绍了Google数据源JSON无效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用其 Python库实现Google数据源.我希望能够使用

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.

但是,即使他们的示例也无法在JSONLint中验证:

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}]}]}

如何调整simplejson'loads'函数以导入上述JSON内容?我认为主要的问题是对象键不是字符串.

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.

当我尝试使用simplejson将上述JSON导入Python时,当前出现预期属性名称:第1行第1列(字符1)"错误.

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.

推荐答案

它被认为是没有字符串键的无效JSON.

It is considered to be invalid JSON without the string keys.

{id:'name',label:'Name',type:'string'}

必须是:

{'id':'name','label':'Name','type':'string'}

根据 Google数据源页面,他们返回无效的JSON.他们没有具体说出来,但是所有示例都在键上没有引号.

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.

这是用于Python的JSON处理器的相当完整的列表,其中详细介绍了它们支持什么格式以及效果如何.大多数不支持非字符串键,但是看来 demjson 会转换它.

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.

easy_install demjson

这篇关于Google数据源JSON无效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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