Adding roAssociativeArray to roArray

Hi I am not sure if its because its late tonight but I cannot seem to solve this issue.
After I add an associative array to an array, I print the count of the array, it comes up as 0.
Based on the documentation I should use Append, to add an Associative Array entry to an Array.

json = fetch_JSON(api_url)
limit=10
ssContentA = CreateObject(“roArray”, limit, true)
ssContentAA = CreateObject(“roAssociativeArray”)

for i=0 to limit-1 step 1

blogname = json.response.liked_posts*.blog_name*
ssContentAA.AddReplace(“TextOverlayBody”,blogname)

ssURL=json.response.liked_posts*.photos[0].original_size.url*
ssContentAA.AddReplace(“url”,ssURL)

ssContentA.Append(ssContentAA) ’ this is correct no???

end for

print ssContentA.Count() ’ comes up as 0 !

Thanks to anyone who can help keep my sanity

AC

I think you want Push() rather than Append(). Push() adds a single object to the end of an array. Append() adds all the objects in one array to the end of another array.

http://sdkdocs.roku.com/display/sdkdoc/ifArray

Right, you can only Append() an roArray to another roArray. It doesn’t make sense to append an AA (what are you appending, the keys or the values?). You should iterate the AA and Push the values you want.

–Mark

“RokuMarkn” wrote:
Right, you can only Append() an roArray to another roArray. It doesn’t make sense to append an AA (what are you appending, the keys or the values?). You should iterate the AA and Push the values you want.

–Mark

What I am trying to do is take my JSON response, and extract only the data I want. The way I currently understand this is that I need to have an array of associative arrays, which will be loaded as content metadata into the roSlideshow. Whether I push or append my associative array ssContentAA into the ssContentA array at location , the output of the final array is all the same data. I verified I am looping through the JSON data and loading it into each ssContentAA okay, by printing each iteration. The problem I am not able to overcome is that each location in the ssContentA array is the same. Here is my latest code:

ssContentA = CreateObject(“roArray”, json.response.liked_posts.count(), true)
ssContentAA = CreateObject(“roAssociativeArray”)

print “[INFO] Preparing Slideshow”
for i=0 to json.response.liked_posts.count()-1

blogname = json.response.liked_posts*.blog_name*
ssURL = json.response.liked_posts*.photos[0].original_size.url 'only get the first photo for now*

’ replace the current entry with new data
ssContentAA[“TextOverlayBody”] = blogname
ssContentAA[“url”] = ssURL

’ print the photo we saved
print “Photo”;i
print ssContentAA.TextOverlayBody;" : ";ssContentAA.url

ssContentA = ssContentAA ’ load aa onto a playlist

end for

print “[TEST] Testing content arrays…”
print “[TEST]”;ssContentA.Count();" Items in ssContentA"

for i=0 to ssContentA.Count()-1
print “photo”;i
for each key in ssContentAA
print key;" =";ssContentAA[key]
end for
end for

The data in all 20 entries in the ssContentA array are the same. I don’t understand. Sorry to be a pita, but please what am I doing wrong?

Also this is how I am loading my slideshow:

ss = CreateObject(“roSlideShow”)
ss.SetMessagePort(port)
ss.SetPeriod(10)
ss.SetContentList(ssContentA)
ss.Show()

I think you should change this line –
ssContentA = ssContentAA ’ load aa onto a playlist

to

ssContentA.Push(ssContentAA*) ’ load aa onto a playlist*

And see what that gets you.

“destruk” wrote:
I think you should change this line –
ssContentA = ssContentAA ’ load aa onto a playlist

to

ssContentA.Push(ssContentAA*) ’ load aa onto a playlist*

And see what that gets you.

I get a Type Mismatch error

Think I solved it. I looked at the USBPlayer DSK code in main.brs. I used the following:

’ replace the current entry with new data

ssContentAA[“TextOverlayBody”] = blogname
ssContentAA[“url”] = ssURL

ssContentA.Push({
TextOverlayBody: blogname
url: ssURL
})

This seems to work fine. You’re right, trying to load an AA into an A does not seem to work.
Thanks.