Convert object to array

I have a properly formatted JSON string message from which I generate a JSONItem with
jmsg.Load(message.data). That works mostly fine - I can extract ordinary key/value pairs with jmsg.Value("server_id") for instance.

My problem is what to do with a jmsg.Value which I know in advance is an array of strings like:
["X54", "JW382", "B52"] (although I usually won’t know how many strings there will be).

I’ve tried

Var v As Variant
v = jmsg.Value("device")
If VarType(v) = Variant.TypeObject Then
    //do something

There exists a test for Variant.TypeArray too but I’m not sure how to use it correctly. The documentation says something about logically ORing it with the vartype of the array element (string) but I don’t see how that can work when VarType(v) returns 9 (the Variant.TypeObject constant).

So, I’m left wondering how to access elements of v (which I know is an array) when v thinks it is an object. Is there some way to cast it from object to array of strings?

Thanks for any help,
chris

here is a example with array usage
https://documentation.xojo.com/topics/file_managment/reading_and_writing_data_in_json_format.html

Thanks Markus, I thought I’d worked through that article before but once you made me look more carefully, I figured out what I was doing wrong.

I was trying to make a new JSONItem out of the mysterious object, same as the example was doing. That was necessary in the example because the array object contained further objects. However I didn’t need that step because my array object contents are just strings. The breakthrough was the realization that I don’t need to convert the object to an array - just cycle through the object by index to reveal the strings. Very simple in the end …

Thanks again,
chris

1 Like