我有一个带有JSON列表的文件,如下所示:
date
它由body
,title
和import json
with open('AEE_2007.json') as f:
data = [json.loads(line) for line in f]
for obj in data[0]: print(obj['body'])
组成。我想通过运行代码阅读第一个正文:
string integers must be integers
然而它会发出以下错误:
def results = []
list1.each{ lst1 ->
def list1WithDifferences = []
def list2WithDifferences = []
def add = false
def match = list2.find{ lst2 -> lst2.cuInfo == lst1.cuInfo && lst2.service == lst1.service }
match.each{k, v ->
if(k != 'name'){
if(v != lst1[k]){
add = true
list1WithDifferences << "*${lst1[k]}*"
list2WithDifferences << "*${v}*"
}else{
list1WithDifferences << v
list2WithDifferences << v
}
}else{
list2WithDifferences << v
}
}
if(add){
results << list1WithDifferences + list2WithDifferences
}
}
println(results)
知道为什么吗?
亲切的问候
答案 0 :(得分:3)
data[0]
是一个字典 - 直接通过键获取值:
print(data[0]['body'])
如果您想要每个字典中的body
值列表:
print([obj['body'] for obj in data])