将JSON数组转换为Python列表 [英] Convert JSON array to Python list

查看:1221
本文介绍了将JSON数组转换为Python列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import json

array = '{"fruits": ["apple", "banana", "orange"]}'
data  = json.loads(array)

那是我的JSON数组,但是我想将Fruits字符串中的所有值转换为Python列表.正确的方法是什么?

That is my JSON array, but I would want to convert all the values in the fruits string to a Python list. What would be the correct way of doing this?

推荐答案

import json

array = '{"fruits": ["apple", "banana", "orange"]}'
data  = json.loads(array)
print data['fruits']
# the print displays:
# [u'apple', u'banana', u'orange']

您拥有了所需的一切. data将是字典,data['fruits']将是列表

You had everything you needed. data will be a dict, and data['fruits'] will be a list

这篇关于将JSON数组转换为Python列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆