非常简单的JSON解码

use*_*941 1 python json simplejson

已经搜索了这个,但是我找到的所有结果对我来说都没有意义,看起来太复杂了.我想使用jsonsimplejson模块来获取对象中字符串的值.

string = '{"name": "Alex"}'
Run Code Online (Sandbox Code Playgroud)

基本上,我想从那里提取'Alex'的值.我该怎么做才能做到这一点?

Gre*_*ill 7

使用该json模块非常简单:

>>> import json
>>> s = '{"name": "Alex"}'
>>> obj = json.loads(s)
>>> obj
{'name': 'Alex'}
>>> obj["name"]
'Alex'
Run Code Online (Sandbox Code Playgroud)

如果你的Python已经足够老了json,那么请使用simplejson:

import simplejson as json
Run Code Online (Sandbox Code Playgroud)