Forum Discussion
Thanks for the reply, speechles! Between then and now I was able to get the task to do the API call properly.
My Task.xml
<?xml version="1.0" encoding="utf-8" ?> <component name="GetSeason" extends="Task"> <interface> <field id = "contenturi" type = "string" /> <field id = "content" type = "assocarray" /> </interface> <script type="text/brightscript"> <![CDATA[ sub init() m.top.functionName = "getAPIResponse" end sub sub getAPIResponse() port = CreateObject("roMessagePort") request = CreateObject("roUrlTransfer") request.setRequest("GET") request.setURL(contenturi) jsonString = request.GetToString() jsonParsed = ParseJson(jsonString) m.top.content = jsonParsed end sub ]]> </script> </component>
m.top.content seems to have the correct value from the returned JSON.
Now the issue I'm facing is how to get that JSON back into my Scene.brs file? And then display it on a RowList item
in my Scene.brs
m.sceneTask.control = "RUN" jsonTest = m.top.content
Now I want the jsonTest to have the value of m.top.content from the Task.xml, when I do the above, the value of jsonTest is roInvalid
I believe getting the value back to Scene.brs works now. The code above was missing an observer. Once set, now my json object is passed back to the Scene.brs as I wanted it with the correct value.
However, my observer function can set the value properly inside the function itself, but I still cannot assign that value to the jsonTest in the other function.
On my brs file I have this
m.sceneTask.observeField("content","gotContent") m.sceneTask.control = "RUN" jsonThatIWantToUse = .... <---- I want this to have the m.sceneTask.content value
Then
sub gotContent() jsonReturned = m.sceneTask.content <-- this has the correct value end sub
- KiranPrasanna3 years agoChannel Surfer
Hello,I am running this file in task.xml
<?xml version=“1.0” encoding=“utf-8" ?>
<!-- Copyright 2016 Roku Corp. All Rights Reserved. -->
<component name=“ContentReader” extends=“Task”>
<script type=“text/brightscript”>
<![CDATA[
sub init()
m.top.functionName = “getAPIResponse”
end sub
sub getAPIResponse()
port = CreateObject(“roMessagePort”)
request = CreateObject(“roUrlTransfer”)
request.setRequest(“GET”)
request.setURL(m.top.contenturi)
jsonString = request.GetToString()
jsonParsed = ParseJson(jsonString)
m.top.content = jsonParsed
end sub
]]>
</script>
</component>And Used this below function in main.brs file
sub Main()
print “in showChannelSGScreen”
m.readXMLContentTask = createObject(“roSGNode”, “ContentReader”)
m.readXMLContentTask.observeField(“content”, “setcontent”)
m.readXMLContentTask.contenturi = “http://www.sdktestinglab.com/Tutorial/content/xmlcontent.xml”
m.readXMLContentTask.control = “RUN”
readData = m.top.content
print “readData”
end subbut this function is not executed in main.brs file
Can you please help me to execute this function from main.brs Or provide the sample examples - NicholasStokes3 years agoBinge Watcher
Hello,I am running this file in task.xml<component name = "ContentReader" extends = “Task” > <interface>
<field id = "contenturi" type = "uri" />
<field id = “content” type = “node” />
</interface> <script type = “text/brightscript” > <![CDATA[ sub init()
m.top.functionName = “getcontent”
end sub sub getcontent()
content = createObject(“roSGNode”, “ContentNode”) contentxml = createObject(“roXMLElement”) readInternet = createObject(“roUrlTransfer”)
readInternet.setUrl(m.top.contenturi)
contentxml.parse(readInternet.GetToString()) if contentxml.getName()=“Content”
for each item in contentxml.GetNamedElements(“item”)
itemcontent = content.createChild(“ContentNode”)
itemcontent.setFields(item.getAttributes())
end for
end if m.top.content = content
end sub ]]> </script></component>And Used this below function in main.brs filesub init() m.readXMLContentTask = createObject(“roSGNode”, “ContentReader”)
m.readXMLContentTask.observeField(“content”, “setcontent”)
m.readXMLContentTask.contenturi = “http://www.sdktestinglab.com/Tutorial/content/xmlcontent.xml”
m.readXMLContentTask.control = “RUN”
end subsub setcontent()
m.content = m.readXMLContentTask.content
m.contentitems = m.content.getChildCount()
m.currentitem = 0end subbut this function is not executed in main.brs file
Can you please help me to execute this function from main.brs Or provide the sample examples