【发布时间】:2014-05-26 03:10:44
【问题描述】:
我从网站上得到如下数据:
{
...
u'rows':[
[
u'mail@example.com',
u'74'
],
[
u'mail2@example.com',
u'1'
],
[
u'mail3@example.com',
u'1'
],
...
],
我只显示了我需要的数据。如何将其转换为 json,例如:
{u'mail@example.com': 74, u'mail2@example.com': 1, u'mail3@example.com': 1, ...}
我可以一个一个地读取元素:
if response.get('rows'):
total = 0
for row in response.get('rows'):
total += int(row[1])
logging.info(row[0]+": "+row[1])
但不确定下一步应该做什么。不要认为我应该只生成字符串。
【问题讨论】:
-
您不应该手动生成 JSON。创建相关的 Python 结构(即字典,使用转换),然后让您的 JSON 库将其转回。
标签: python json google-app-engine python-2.7 simplejson