Forum Discussion

EvilPounders's avatar
9 months ago

m.global from remote url json response

Hello, I need set the serverurl value from a json response of external url.

My MainScene.brs had this code:

m.global.addFields({serverurl: "https://host/endpoint", row: "", items: "", info: "", play: "", user: "", pass: "", expire: ""})

 

I tried to add this:

request = CreateObject("roUrlTransfer")
request.SetUrl("http://host/info.json")
html = request.GetToString()
data = html.Trim()
json = ParseJSON(data)
host = json.host.toStr()
name = json.name.toStr()

m.global.addFields({serverurl: host, row: "", items: "", info: "", play: "", user: "", pass: "", expire: ""})

I'm getting this error:

BRIGHTSCRIPT: ERROR: roUrlTransfer: creating MAIN|TASK-only component failed on RENDER thread: pkg:/components/MainScene.brs(11)

I tryied to add that code to main.brs and get this:

 

Interface not a member of BrightScript Component (runtime error &hf3) in pkg:/source/main.brs(16)
Backtrace:
#0 Function main() As Void
file/line: pkg:/source/main.brs(16

What is the correct or propper way to set global variable from url request?

No RepliesBe the first to reply