有没有办法用数组值生成 n 行

Is there any way to generate n number of lines with array values

我有 json 个文件并遍历每个 json 对象

我的 JSON 文件:

{
 "User" :{"name":["Eagle","Humming Bird"]}
}

Python代码:

 for j in json.object:
     print j
 print j

每当我运行 python 时,输出都是“蜂鸟”最后一个对象

我需要获取所有对象 我的预期输出:

  Bird : Eagle
  Bird : Humming Bird

如果json文件有2个对象,那么它会像这样生成上面的2个语句

在您的 json 对象中,您有一个键:“User”,其值是另一个 json/dict ,并且您正在尝试访问作为键值的鸟类列表:内部对象中的“名称”。

所以基本上您只需要在您的代码中指定它,方法如下:

import json
x = '{"User" : {"name":["Eagle","Humming Bird"]} }'
y = json.loads(x)
for bird in y["User"]["name"] :
    print("Bird : ",bird)