我有一个(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)
任何方式?
谢谢
答案 0 :(得分:1)
你真正想要的是
{"templates":["Main Screen", "dummy"]}
在python中,您可以使用templates[0]
或templates[1:]
,这是一个比templates["0"]
或templates.get("0")
更好的API。