Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
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
EnTerr
Level 8

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