本文介绍了使用Python从JSON获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试从JSON字符串中检索值时,它给了我一个错误:
While I am trying to retrieve values from JSON string, it gives me an error:
data = json.loads('{"lat":444, "lon":555}') return data["lat"]但是,如果我遍历数据,它将为我提供元素(lat和lon),但没有值:
But, if I iterate over the data, it gives me the elements (lat and lon), but not the values:
data = json.loads('{"lat":444, "lon":555}') ret = '' for j in data: ret = ret + ' ' + j return ret哪个返回:lat lon
我需要怎么做才能获得lat和lon的值? (444和555)
What do I need to do to get the values of lat and lon? (444 and 555)
推荐答案如果要遍历字典的键和值,请执行以下操作:
If you want to iterate over both keys and values of the dictionary, do this:
for key, value in data.items(): print key, value更多推荐
使用Python从JSON获取值
发布评论