Forum Discussion

gabriel_parrale's avatar
9 years ago

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

1 Reply

  • 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>
    ]