args = {'series': 'exr|usd|gbp', 'K': 2, 'M': 2, 'tau': 1}
args = json.loads(args)
Traceback (most recent call last):
File "/home/ubuntu/workspace/chaos/chaos_worker.py", line 12, in <module>
args = json.loads(args)
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 1 (char 1)
答案 0 :(得分:4)
等等,你是否正在将python dict转换为json?在这种情况下,使用json.dumps
。您在第一行定义的args
实际上是dict
。
args = {'series': 'exr|usd|gbp', 'K': 2, 'M': 2, 'tau': 1}
print args.__class__
Out: dict
args = json.dumps(args)
print args
Out: '{"series": "exr|usd|gbp", "K": 2, "M": 2, "tau": 1}'
按预期在json可解析字符串中。