The following code runs with no issue in my app using Xojo 2023r3
Public Function ToStringArray(Extends json As JSONItem) As String()
Dim result() As String
If json Is Nil Then Return result
If Not json.IsArray Then Return result
Dim LastItemIndex As Integer = json.Count - 1 // Get exception here with 2023r4 and 2024r1
For i As Integer = 0 To LastItemIndex
result.Append json(i).StringValue
Next
Return result
End Function
However, when my app runs this code using Xojo 2023r4 or 2024r1, I get a TypeMismatchException on the line noted. This occurs when the methodās JSONItem is passed ["Test"]
If I create a test app using 2023r4 or 2024r1 containing just this method and pass it ["Test"] there is no issue. Can anyone see why this is happening with my main app or suggest a way to isolate whatās causing the issue?
The only way I could find to trigger a TypeMismatchException in that method was with value type mixing for something that canāt be converted to a string, and that happened on the Append line. I used this JSON data to get that result:
["Test", {"a":"b"}]
Iād double-check that the data youāre converting to a JSONItem is what you expect it to be in your main project since it works in a simpler test project. Thatās the only cause I can think of.
Thanks @Anthony_G_Cyphers for looking into this. Yes itās odd. The TypeMismatchException in my main app though is happing on this line:
And above Iāve provided a screen shot of the ājsonā value ["Test"] from the main app, showing the binary data to make sure there isnāt some obscure hidden characters in there. Looks identical to what is in my test app that works.
Thereās nothing intermittent about it, happens every time I try.
Public Function ToStringArray(Extends json As JSONItem) As String()
Var result() As String
If json Is Nil Or (Not json.IsArray) Then Return result
For i As Integer = 0 To json.LastRowIndex
result.Append json.ValueAt(i).StringValue
Next
Return result
End Function
Break there and inspect ājsonā contents. I guess thereās something broken in that data.
By the way, I missed one new syntax change. Append() was deprecated in favor of Add()
Public Function ToStringArray(Extends json As JSONItem) As String()
Var result() As String
If json Is Nil Or (Not json.IsArray) Then Return result
For i As Integer = 0 To json.LastRowIndex
result.Add json.ValueAt(i).StringValue
Next
Return result
End Function
Yes I get that if I place this āToStringArrayā method in a new project it works with the data that is seen in my production app. The issue is it doesnāt work in my actual app when using Xojo 2023r4 or 2024r1.
Iāve been able to create a cut-down project that illustrates this and have posted a confidential issue on https://tracker.xojo.com.
Just providing an update on this. Iāve supplied a project to Xojo via a confidential issue that demonstrates the bug. As of two weeks ago it has had a status of reproducible. Hopefully it wonāt take too long for this to get looked at.
Happy to report that this bug was fixed in Xojo2024r3. I finally had the chance today to install and test with Xojo 2024r3.1 and all looks good.
@Rick_Araujo I deleted the confidential attachments to the issue report but canāt find a way to make it public. Although there isnāt much to see as itās just Javier changing milestones and reporting that itās fixed in 2024r3.