答案 0 :(得分:3)
您可以使用json.loads
来解析json字符串
>>> data=['{"time":["1000","MS"],"What is your name?":["John"]}']
>>> a_dict = json.loads(data[0])
>>> a_dict.keys()
[u'What is your name?', u'time']
>>> a_dict.values()
[[u'John'], [u'1000', u'MS']]
现在,您可以使用简单的for
循环来打印所需的输出。
或者喜欢
>>> print '\n'.join(a_dict.keys())
What is your name?
time
>>> print '\n'.join( '\n'.join(x )for x in a_dict.values() )
John
1000
MS
答案 1 :(得分:0)
您还可以使用ast
模块:
>>> import ast
>>> ast.literal_eval(data[0])
{'What is your name?': ['John'], 'time': ['1000', 'MS']}
>>> d=ast.literal_eval(data[0])
>>> print '\n'.join(d.keys())
What is your name?
time
>>> print '\n'.join([j for i in d.values() for j in i])
John
1000
MS