Roku:动态 url return 为空的 roUrlTransfer
Roku: roUrlTransfer with dynamic url return empty
我正在构建一个调用两个 xml 文件的频道,第一个包含将在每一行中显示的内容的链接,第一个调用它工作正常,因为我使用的是静态 url
url = CreateObject("roUrlTransfer")
url.SetUrl("http://theRowsContents.xml")
rsp = url.GetToString()
responseXML = ParseXML(rsp)
responseXML = responseXML.GetChildElements()
'responseArray = responseXML.GetChildElements()
result = []
for each xmlItem in responseXML
item = {}
item.TITLE = xmlItem.getAttributes().title
item.ContentList = GetApiArray(xmlItem.getAttributes().feed)
result.push(item)
end for
但是当我通过第二个 url 来获取内容时,它不起作用
Function GetApiArray(url as String)
newXfer = CreateObject("roUrlTransfer")
newXfer.SetUrl(url)
response = newXfe.GetToString()
responseXML = ParseXML(response)
responseXML = responseXML.GetChildElements()
responseArray = responseXML.GetChildElements()
这是日志
> Suspending threads... Thread selected: 0* pkg:/source/main.brs(112)
> responseXML = responseXML.GetChildElements()
>
> Current Function: 106: Function GetApiArray(url as String) 107:
> newXfer = CreateObject("roUrlTransfer") 108: newXfer.SetUrl(url)
> 109: response = newXfer.GetToString() 110: 111:
> responseXML = ParseXML(response) 112:* responseXML =
> responseXML.GetChildElements() 113: responseArray =
> responseXML.GetChildElements() 114: 115: result = [] 116:
> 'Dot' Operator attempted with invalid BrightScript Component or
> interface reference. (runtime error &hec) in pkg:/source/main.brs(112)
> 112: responseXML = responseXML.GetChildElements() Backtrace:
> #2 Function getapiarray(url As String) As Dynamic file/line: pkg:/source/main.brs(112)
> #1 Function makerequest() As Dynamic file/line: pkg:/source/main.brs(54)
> #0 Function runuserinterface() As Void file/line: pkg:/source/main.brs(15) Local Variables: url roString
> (2.1 was String) refcnt=2 val:"https://contentsFeed.xml" global
> Interface:ifGlobal m roAssociativeArray refcnt=4
> count:1 newxfer roUrlTransfer refcnt=1 response
> roString (2.1 was String) refcnt=1 val:"" responsexml Invalid
> responsearray <uninitialized> result <uninitialized> xmlitem
> <uninitialized> itemaa <uninitialized> item
> <uninitialized> Threads: ID Location
> Source Code 0* pkg:/source/main.brs(112) responseXML
> = responseXML.GetChildElements() *selected
>
> Brightscript Debugger>
所以我做错了什么?
您在第 109 行有错别字 ;)
您正在使用 newXfe
而不是 newXfer
。
看到错误:
'Dot' Operator attempted with invalid BrightScript Component or
interface reference. (runtime error &hec) in pkg:/source/main.brs(109)
那是因为 newXfe
未初始化(很明显)。
我正在构建一个调用两个 xml 文件的频道,第一个包含将在每一行中显示的内容的链接,第一个调用它工作正常,因为我使用的是静态 url
url = CreateObject("roUrlTransfer")
url.SetUrl("http://theRowsContents.xml")
rsp = url.GetToString()
responseXML = ParseXML(rsp)
responseXML = responseXML.GetChildElements()
'responseArray = responseXML.GetChildElements()
result = []
for each xmlItem in responseXML
item = {}
item.TITLE = xmlItem.getAttributes().title
item.ContentList = GetApiArray(xmlItem.getAttributes().feed)
result.push(item)
end for
但是当我通过第二个 url 来获取内容时,它不起作用
Function GetApiArray(url as String)
newXfer = CreateObject("roUrlTransfer")
newXfer.SetUrl(url)
response = newXfe.GetToString()
responseXML = ParseXML(response)
responseXML = responseXML.GetChildElements()
responseArray = responseXML.GetChildElements()
这是日志
> Suspending threads... Thread selected: 0* pkg:/source/main.brs(112)
> responseXML = responseXML.GetChildElements()
>
> Current Function: 106: Function GetApiArray(url as String) 107:
> newXfer = CreateObject("roUrlTransfer") 108: newXfer.SetUrl(url)
> 109: response = newXfer.GetToString() 110: 111:
> responseXML = ParseXML(response) 112:* responseXML =
> responseXML.GetChildElements() 113: responseArray =
> responseXML.GetChildElements() 114: 115: result = [] 116:
> 'Dot' Operator attempted with invalid BrightScript Component or
> interface reference. (runtime error &hec) in pkg:/source/main.brs(112)
> 112: responseXML = responseXML.GetChildElements() Backtrace:
> #2 Function getapiarray(url As String) As Dynamic file/line: pkg:/source/main.brs(112)
> #1 Function makerequest() As Dynamic file/line: pkg:/source/main.brs(54)
> #0 Function runuserinterface() As Void file/line: pkg:/source/main.brs(15) Local Variables: url roString
> (2.1 was String) refcnt=2 val:"https://contentsFeed.xml" global
> Interface:ifGlobal m roAssociativeArray refcnt=4
> count:1 newxfer roUrlTransfer refcnt=1 response
> roString (2.1 was String) refcnt=1 val:"" responsexml Invalid
> responsearray <uninitialized> result <uninitialized> xmlitem
> <uninitialized> itemaa <uninitialized> item
> <uninitialized> Threads: ID Location
> Source Code 0* pkg:/source/main.brs(112) responseXML
> = responseXML.GetChildElements() *selected
>
> Brightscript Debugger>
所以我做错了什么?
您在第 109 行有错别字 ;)
您正在使用 newXfe
而不是 newXfer
。
看到错误:
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/source/main.brs(109)
那是因为 newXfe
未初始化(很明显)。