1
我有寻找这个,但我觉得所有的结果对我来说没有意义,似乎太复杂了。我正在寻找使用json
或simplejson
模块来获取我的对象中的字符串的值。非常简单的JSON解码
string = '{"name": "Alex"}'
基本上,我想从中提取'Alex'值。我该怎么做才能做到这一点?
我有寻找这个,但我觉得所有的结果对我来说没有意义,似乎太复杂了。我正在寻找使用json
或simplejson
模块来获取我的对象中的字符串的值。非常简单的JSON解码
string = '{"name": "Alex"}'
基本上,我想从中提取'Alex'值。我该怎么做才能做到这一点?
这是使用json
module非常简单:
>>> import json
>>> s = '{"name": "Alex"}'
>>> obj = json.loads(s)
>>> obj
{'name': 'Alex'}
>>> obj["name"]
'Alex'
如果你的Python是足够大,它没有json
,然后用simplejson
代替:
import simplejson as json
为什么不尝试阅读文档第一?它的拼写很清楚,在http://docs.python.org/library/json.html
哪里?我看不出有关解码简单JSON对象的任何内容。 – user1447941
@ user1447941尝试再次查找。 http://docs.python.org/library/json.html#json.loads –