python - 非常 simplejson 解码

标签 python json simplejson

搜索过这个,但我发现的所有结果对我来说都毫无意义,而且似乎太复杂了。我希望使用 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/

相关文章:

python - 来自 csv 的 Keras 文本分类自定义数据集

python - Scikit Learn 中的 CountVectorizer

python - 什么更快 - 将 pickle 字典对象加载或加载 JSON 文件 - 到字典?

python - 如何为 Python 安装 SimpleJson 包

python - 将一个巨大的json字符串反序列化为python对象

python - 从 AWS SageMaker 访问 Google BigQuery

python - 字节到字符串到字节。 python 3

javascript - 根据 AngularJS 中另一个选择元素的值设置选择选项

java - 从 URL 中的 JSON 创建 Java 数组

iOS UiCollectionView - 使用自定义 UiCollectionViewLayout 重新加载数据