Another Auto Casting Question

I see the advantage of Auto over Variant but I do find it too verbose.

I’m converting some JSON to a Xojo.Core.Dictionary with the Xojo.Data.ParseJSON command. All is well. The result is stored in a Xojo.Core.Dictionary called data. The JSON contains an array of tags, so data.Value("tags") becomes an Auto array holding the tags I want to get at.

All I’m trying to do is convert the Auto array within the Xojo.Core.Dictionary to a Text array. The following seems to work but I’m hoping there is a faster or more elegant way (as looping seems inefficient):

If data.HasKey("tags") Then Dim autoArray() As Auto = data.Value("tags") Dim textArray() as Text data.Remove("tags") ' don't want this anymore For Each tag As Auto In autoArray textArray.Append(CType(tag, Text)) Next tag End If

Is there a better way? I’ve tried several but I keep getting TypeMismatch errors

Does for each tag as text in autoArray work?

Thanks. Knew there must be a simpler approach.

simpler, but for each is ever so slightly slower. At least it was when I benchmarked it for some things. Doesn’t matter for 10 or 20 variables, but might matter a lot for 100k.

Interesting. I use For…Each extensively in my app for clarity of reading. What kind of performance hit are we talking compared to a normal loop?

I also use it extensively, I only noticed because I was trying to shave as much as possible off some very large methods. Unless you have hundreds of thousands of entries to walk or you care about 1 or 2 extra ms it won’t make any difference. I can’t recall the exact numbers from my testing and I still use it everywhere. But in something you’re trying to shave every MS off of it’s something you can consider.

Also remember that For Each does not guarantee the same order.