0

我是 python 新手,我很确定我在做一些非常愚蠢的事情。

我有一个字符串:

s = '{"l":1,"oE":{"n":"name","rN":["1","2","3","3","5","6","7","8","9","10"],"dir":"out","ed":["1","1","1","1","1","1","1","1","1","1"]}'

我做了 json.loads(s)

但我得到一个错误?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/json/__init__.py", line 328, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 381, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 1 column 72 (char 72)
4

2 回答 2

2

您的代码中缺少引号。也是一个闭括号。代替:

s = '{"l":1,"oE":{"n":"name","rN":["1","2","3","3","5","6","7","8","9","10],"dir":"out","ed":["1","1","1","1","1","1","1","1","1","1"]}'

采用

s = '{"l":1,"oE":{"n":"name","rN":["1","2","3","3","5","6","7","8","9","10"],"dir":"out","ed":["1","1","1","1","1","1","1","1","1","1"]}}'

您可以从堆栈跟踪中弄清楚这一点:

ValueError: Expecting , delimiter: line 1 column 72 (char 72)

如果您查看该行中的第 72 个字符,您将看到错误发生的地方。

于 2013-02-20T22:23:26.780 回答
0

"10]好像少了一个"。试试"10"]吧。

于 2013-02-20T22:23:06.547 回答