[英]I am trying to get the values associated with name in my json output in python. I dont know how to do it
import urllib.request
import json
import io
from urllib.request import urlopen
u=io.TextIOWrapper(urlopen('https://api.locu.com/v1_0/venue/search/?locality=Atlanta&postal_code=30301&category=restaurant&api_key=xxxxx'),encoding='latin1')
text=u.read()
print (text)
output is as follows:
{"meta": {"limit": 25, "cache-expiry": 3600}, "objects": [{"name": "Mali Restaurant", "locality": "Atlanta", "street_address": "961 Amsterdam Ave.", "cuisines": [], "region": "GA", "long": -84.355387, "phone": "(404) 874-1411", "postal_code": "30301", "categories": ["other", "restaurant"], "has_menu": true, "country": "United States", "lat": 33.787547, "id": "c0f62e6ab2d8ed4a169f", "website_url": ", "resource_uri": "/v1_0/venue/c0f62e6ab2d8ed4a169f/"}, {"name": "Coca-Cola CCP Cafe", "locality": "Atlanta", "street_address": "One Coca-Cola Plaz", "cuisines": [], "region": "GA", "long": -84.3976825046326, "phone": null, "postal_code": "30301", "categories": ["other", "restaurant"], "has_menu": false, "country": "United States", "lat": 33.7713581924234, "id": "c4970097bd8b63fad908", "website_url": null, "resource_uri": "/v1_0/venue/c4970097bd8b63fad908/"}, {"name": "Boner's", "locality": "Atlanta", "street_address": "634 Fraser St.", "cuisines": [], "region": "GA", "long": -84.386258, "phone": "(404) 659-9000", "postal_code": "30301", "categories": ["restaurant"], "has_menu": true, "country": "United States", "lat": 33.737016, "id": "f5bf05f7d9bbc609a1d1", "website_url": ", "resource_uri": "/v1_0/venue/f5bf05f7d9bbc609a1d1/"}]}
I would like to get the values of "name".我想获得“名称”的值。 what do i do?我该怎么办?
There is an error in that text, this is not valid JSON:该文本中有错误,这不是有效的 JSON:
"website_url": ", "resource_uri":
But if it was valid JSON, you could just do this...但如果它是有效的 JSON,你可以这样做......
j = json.loads(text)
for node in j['objects']:
if 'name' in node:
print (node['name'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.