可以使用Python中的内置模块json来将JSON数据添加到数组中。具体方法如下:

  1. 创建一个空数组。
array = []
  1. 将JSON数据解析为Python字典。
import json

json_data = '{"name": "John", "age": 30, "city": "New York"}'
dict_data = json.loads(json_data)
  1. 将Python字典添加到数组中。
array.append(dict_data)

完整的代码示例:

import json

# 创建一个空数组
array = []

# 将JSON数据解析为Python字典
json_data = '{"name": "John", "age": 30, "city": "New York"}'
dict_data = json.loads(json_data)

# 将Python字典添加到数组中
array.append(dict_data)

# 打印数组
print(array)

输出结果为:

[{'name': 'John', 'age': 30, 'city': 'New York'}]
python把json加入数组

原文地址: http://www.cveoy.top/t/topic/bmgC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录