Developers

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
Tags (1)
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>
]
Tags (1)
0 Kudos
Community is Being Upgraded!

We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.

Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality. In the meantime, for additional assistance, visit our Support Site.

We're sorry for this disruption — we’re excited to share what’s next!