gpt4 book ai didi

python - 非常 simplejson 解码

转载 作者:太空宇宙 更新时间:2023-11-04 07:10:59 30 4
gpt4 key购买 nike

搜索过这个,但我发现的所有结果对我来说都毫无意义,而且似乎太复杂了。我希望使用 jsonsimplejson 模块来获取对象中字符串的值。

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

关于python - 非常 simplejson 解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10973316/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com