GenerateJson

I´m in the process of eliminating all text vars in my iOS app and switching to string.
GenerateJSON and dictionaries seem to expect text though:

Var d1 As New Dictionary
d1.Value("Test") = "Text"
Var json1 As String
json1 = GenerateJSON(d1) //works (debugger shows the value of Test as beeing of type text)

var s as String = "String"
Var d2 As New Dictionary
d2.Value("Test") = s
Var json2 As String
json2 = GenerateJSON(d2) //crash

Am I doing something wrong?

This code doesn’t crash here for iOS or desktop project in Xojo 2023r2.

Do you have details on the crash?

Or did the debugger crash instead of the framework?

Debugger/iOS Simulator crashes as soon as
json2 = GenerateJSON(d2)
is executed.

Unfortunately I got something urgent on the desk right now.
Might be a while til I can return to this topic…

What version of Xojo are you using? The latest version of GenerateJSON return String, not Text. Older versions returned Text, but it’s been a while.

Where are you putting this code?
Is the super Mobile or IOS?
Is this a new project?

2023r2. It´s not about the returned value, it crashes when I pass strings in the dictionary as parameter.

It is in a debug-button on the homeview (MobileScreen) of my app.
Super is Mobile.
It´s an old project (from 2016). Just switched everything from ios… to mobile… and changing text to string everywhere.

My guess is something still left that needs/produce text.

Maybe the IDE is trying to use Xojo.Data.GenerateJSON (that uses Text) instead of just GenerateJSON (that uses String)

I created a small project to demonstrate the crash:
Crashtest

Could be but where do I find that?

I have never used Xojo iOS (I don’t have setup to run it either) but I think you need to turn Simple References OFF:
image

That option is to avoid defining the named component (Xojo.Data.GenerateJSON) and just use GenerateJSON in your code.

1 Like

Yes, that was it. Thank you very much.

1 Like

Today I learned something. (Didn’t even know this option existed)

Thanks for your often-insightful posts, Alberto!

Anthony

2 Likes

If I were you, I will start with a clean new project with Xojo2023r2 and add the code to it, I see several things different from your sample project and a new clean iOS project. As I don’t have iOS experience, I don’t know what else changed (besides the Simple References) setting that may be missing from a 2016 base project.

1 Like

Is no longer available in current Xojo (from what I see on a new iOS project)

Yes, that crashes!

is there a Xojo Issue already?

I was hoping I could avoid starting from scratch.
I´ll see how far I get and keep starting over as an emergency fallback.

Nope, Alberto showed me the magic setting that made it work :slight_smile:

I made an issue:
https://tracker.xojo.com/xojoinc/xojo/-/issues/73772