简体   繁体   English

我试图在 python 的 json 输出中获取与 name 关联的值。 我不知道该怎么做

[英]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.

相关问题 我正在尝试在 python 中创建一个密码系统。 我不知道这有什么问题 - i am trying to make a password system in python. i dont know whats wrong with this python——我正在尝试学习 python。 为什么我没有得到任何 output.? - python--am trying to learn python. Why do i not get any output.? 我想将dataframe的值替换为python中的列名。 我应该怎么做? - I want to replace values of dataframe as a column name in python. How am I suppose to do that? 在Python中使用urllib2。 如何获取我正在下载的文件的名称? - Using urllib2 in Python. How do I get the name of the file I am downloading? 我正在尝试使用 python 从 postgressql 中的列中提取一个值。 但我总是收到这个错误: - I am trying to extract a values from column in postgressql with python. But i always get this error : 我正在尝试制作一个程序来查找圆的面积,作为我在 python 中的第一个项目。有人知道我做错了什么吗? - I am trying to make a program that finds the area of a circle as my first project in python. does anything know what I did wrong? 我正在尝试从 HTML 文件中获取文本,但我不知道如何(谷歌搜索但 idk 去哪里看) - I am trying to get text from an HTML file, but I dont know how(googled but idk where to look) 如何在python中使用mysql数据库调试cgi脚本。 我是如何调试的新手 - How do i debug my cgi script with mysql database in python. I am new to how to debugg 当我运行python文字游戏时,出现属性错误,我不知道如何解决 - when i run my python text game i get a attribute error i dont know how to solve 我不小心用 Python 在我的桌面上创建了大量文件。 我该如何摆脱它们? - I accidentally created a huge amount of files on my Desktop with Python. How do I get rid of them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM