Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用simplejson提取值?_Python_Simplejson - Fatal编程技术网

Python 如何使用simplejson提取值?

Python 如何使用simplejson提取值?,python,simplejson,Python,Simplejson,我有以下json字符串: {"response":[[{"uid":123456,"name":"LA_"}],[{"cid":"1","name":"Something"}],[{"cid":1,"name":"Something-else"}]]} 我怎样才能得到有价值的东西? 我做以下几点 jstr = json.loads(my_string) if jstr.get('response'): jstr_response = jstr.get('response')[1].ge

我有以下json字符串:

{"response":[[{"uid":123456,"name":"LA_"}],[{"cid":"1","name":"Something"}],[{"cid":1,"name":"Something-else"}]]}
我怎样才能得到有价值的东西? 我做以下几点

jstr = json.loads(my_string)
if jstr.get('response'):
    jstr_response = jstr.get('response')[1].get('name')
但它不起作用“list”对象没有属性“get”

试试这个

jstr = json.loads(my_string)
if jstr.get('response'):
    jstr_response = jstr.get('response')[1][0].get('name')

它是一个映射到字典列表的字典:jstr.get'response'[1][0]。get'name'