在python中读取json值时出现无效参数错误
在python中读取外部json文件的值时出现无效参数错误 我试过:在python中读取json值时出现无效参数错误,python,json,python-3.x,Python,Json,Python 3.x,在python中读取外部json文件的值时出现无效参数错误 我试过: import json with open('https://www.w3schools.com/js/json_demo.txt') as json_file: data = json.load(json_file) #for p in data['people']: print('Name: ' + data['name']) 给了我一个错误: 以json_文件形式打开(“”):OSError:
import json
with open('https://www.w3schools.com/js/json_demo.txt') as json_file:
data = json.load(json_file)
#for p in data['people']:
print('Name: ' + data['name'])
给了我一个错误:
以json_文件形式打开(“”):OSError:[Errno 22]无效参数:
''
使用
使用
由于
open
用于打开本地文件,而不是so注释的URL,因此请使用so注释的URL
尽管他提供的链接是针对python-2
试试这个(python-3
):
约翰
由于
open
用于打开本地文件,而不是so注释的URL,因此请使用so注释的URL
尽管他提供的链接是针对python-2
试试这个(python-3
):
约翰
open
用于打开本地文件,而不是URL。@jonrsharpe那么该用什么?如果你想坚持使用标准库,请参阅。有人能帮我:1)和2)open
用于打开本地文件,而不是URL。@jonrsharpe那么该用什么?如果你想坚持使用标准库,看,有人能帮我吗:1)和2)
import requests
response = requests.get('https://www.w3schools.com/js/json_demo.txt')
response.encoding = "utf-8-sig"
data = response.json()
print(data['name'])
>>> John
import json
from urllib.request import urlopen
with urlopen('https://www.w3schools.com/js/json_demo.txt') as json_file:
data = json.load(json_file)
#for p in data['people']:
print('Name: ' + data['name'])