有一个数字作为json的标识符

时间:2014-05-17 00:27:06

标签: python json

我有一个(python)json,目前看起来像这样

{"templates":{"Main Screen":0,"dummy":1}}

我想拥有的是

{"templates":{0:"Main Screen",1:"dummy"}}

但是json不再解码它了

self.fileData=json.loads(self.VDfile.readlines()[0])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 15 (char 14)

任何方式?

谢谢

1 个答案:

答案 0 :(得分:1)

你真正想要的是

{"templates":["Main Screen", "dummy"]}

在python中,您可以使用templates[0]templates[1:],这是一个比templates["0"]templates.get("0")更好的API。