【发布时间】:2015-06-25 12:45:18
【问题描述】:
{"0":{"posted_date":"2015 年 6 月 25 日"},"1":{"posted_date":"2015 年 6 月 26 日"}}
注意:
- '0'和'1'是变量-'count',变量是通过repeat/loop生成的
- “posted_date”是一个字符串
- “2015 年 6 月 25 日”和“2015 年 6 月 26 日”也是可变的 - '日期'
如何使用 python 创建像上面这样的 JSON 输出?
[编辑无效的代码]
import json
final = []
count = 0
postID = 224
while postID < 1200:
final.append({count: {"posted_ID":postID}})
count = count + 1
postID = postID * 2
print str(json.dumps(final))
【问题讨论】:
-
第一步:写代码!
-
@Kasra of coz,无论如何这是我的(错误)代码:请看上面(已编辑)