通过代码打开json文件链接 [英] Open json file link through a code
问题描述
我正在创建插件,并且正在修改py文件中的某些函数. 我打算做的是以下代码,我有此代码:
I'm creating an addon and I'm modifying some functions that come within a py file. What I intend to do is the following, I have this code:
def channellist():
return json.loads(openfile('lib.json',pastafinal=os.path.join(tugapath,'resources')))
此代码可访问资源子文件夹中tugapath文件夹内的lib.json文件.我所做的就是将lib.json文件放入保管箱,并希望将其替换为lib.json文件中的保管箱链接,而不是调用文件夹.
This code gives access to a lib.json file that is inside the tugapath folder in the resources subfolder. What I did was put the lib.json file in the dropbox and wanted to replace it with the dropbox link from the lib.json file instead of calling the folders.
我试图更改代码,但没有成功.
I tried to change the code but without success.
def channellist():
return json.loads(openfile('lib.json',pastafinal=os.path.join("https://www.dropbox.com/s/sj1246qtiodm6qd/lib.json?dl=1')))
如果有人可以帮助我,我将不胜感激! 首先谢谢你.
If someone can help me, I'm grateful! Thank you first.
推荐答案
鉴于您的链接包含有效的json-您发布的内容并非如此-您可以使用请求.
Given that your link holds valid json - which is not the case with the content you posted - you could use requests.
如果Dropbox上的内容看起来像这样:
If the content at dropbox looked liked this:
{"tv":
{"epg": "tv",
"streams":
[{"url": "http://topchantv.net:3456/live/Stalker/Stalker/838.m3u8",
"name": "IPTV",
"resolve": False,
"visible": True}],
"name": "tv",
"thumb": "thumb_tv.png"
}
}
然后获取内容就是这样
import requests
url = 'https://www.dropbox.com/s/sj1246qtiodm6qd/lib.json?dl=1'
r = requests.get(url)
json_object = r.json()
因此,如果您需要在函数中使用它,我想您应该输入url并返回json,如下所示:
So if you needed it inside a function, I guess you'd input the url and return the json like so:
def channellist(url):
r = requests.get(url)
json_object = r.json()
return json_object
这篇关于通过代码打开json文件链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!