Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create roArray of roAssociativeArrays

For example I need to creat the following and pass it to the respective content node (Streams - roArray of roAssociativeArrays😞



url : "http://me.com/x-384.mp4", 
bitrate : 384 
quality : false 
contentid : "x-384" 
}, 

url : "http://me.com/x-2500.mp4"
bitrate : 2500 
quality : true 
contentid : "x-1500" 

]

This data comes to me in a json but as I transform an array of associativearrays assuming that I am inside the json loop
0 Kudos
1 REPLY 1
EnTerr
Roku Guru

Re: How to create roArray of roAssociativeArrays

I assume you are asking "how do i convert a JSON string to a BrightScript data structure?". That's very easy actually and rather pleasant - just use parseJSON() function - and formatJSON() in the opposite direction. Here is example on going forth and back:

Brightscript Debugger> bs = [ { url: "http://me.com/x-384.mp4", bitrate: 384, quality: false, contentid: "x-384" }, { url: "http://me.com/x-2500.mp4", bitrate: 2500, quality: true, contentid: "x-1500" } ]: ? bs
<Component: roArray> =
[
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
]

Brightscript Debugger> js = formatJSON(bs): ? js
[{"bitrate":384,"contentid":"x-384","quality":false,"url":"http://me.com/x-384.mp4"},{"bitrate":2500,"contentid":"x-1500","quality":true,"url":"http://me.com/x-2500.mp4"}]

Brightscript Debugger> js2bs = parseJSON(js): ? js2bs
<Component: roArray> =
[
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
]
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.