我正在使用他们的Google数据源来实现Python库 http://code.google.com/apis/visualization/documentation/dev/gviz_api_lib.html#tojsonexample。我希望能够使用以下命令将库的响应导入到另一个 Python 脚本中simplejson 库。 http://simplejson.googlecode.com/svn/tags/simplejson-2.0.9/docs/index.html
然而,即使是他们的example http://google-visualization.appspot.com/python/dynamic_example不在 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)”错误。