How to select a random JSON element from this JSON string

Hi Everyone,

I know XDC2016 is in full swing so now might not be the best time to ask questions here but I hope some of you are still out there! I have the following JSON encoded string:

{ "colors_available":[ {"color":"red"}, {"color":"green"}, {"color":"blue"}, {"color":"black"} ] }

And I need to select a random 2 colors from it. I’m not sure how to do that. I’m sure it has something to do with JSONItem but I’m not really sure how to proceed.

Can anyone help?


dim j as new Xojo.Core.Dictionary = Xojo.Data.ParseJSON( jsonText )
dim colors() as Auto = j.Value( "colors_available" )
// Now colors will have 4 elements, each a Xojo.Core.Dictionary with one value.
// Randomly select as needed.

Great! That seems easy enough. Is the process similar for Xojo Classic? I’m not using the new framework yet and I’m still on 2014 for a bit.

Yes, JSONItem will work similarly.

Thank you!