字符串函数在Python中不处理JSON字符串
我从api中提取了以下数据,并将其转换为字符串以对其执行字符串操作字符串函数在Python中不处理JSON字符串,json,python-3.x,Json,Python 3.x,我从api中提取了以下数据,并将其转换为字符串以对其执行字符串操作 import urllib.request def f1(): strurl=urllib.request.urlopen("https://api.somedateapi.io") info=strurl.read() print(info) part1=list(info.split(",")) print (part1) f1() 它给出了列表的类型错误(str.split(
import urllib.request
def f1():
strurl=urllib.request.urlopen("https://api.somedateapi.io")
info=strurl.read()
print(info)
part1=list(info.split(","))
print (part1)
f1()
它给出了列表的类型错误(str.split())-
当我尝试使用str.index(“”)时,也是同样的错误
请告诉我如何对其执行字符串操作?.read()
返回错误提示的字节字符串。使用decode
获取str
对象:
info = strurl.read().decode()
info = strurl.read().decode()