Encoding JSON in Desktop vs Android

Hi All!
I’m a new user and newbie with Xojo. (But an old developer with other tools).
I’m just trying to develop an android app and found some problems that may be something that i ignore.

The android app will check the user with a webservice server (made with Xojo too).
If I try with an application made for desktop all works fine: encode the json message and send it to the server in the body POST.
But when i try the same code in Android I have got a different json.

I also try with a simple app that only do the json string and i have got the same thing.
The code is:

Var e As New Dictionary
e.Value(“usuario”) = “e”
e.value(“clave”) = “1”
Var item As New JSONItem
item.Value(“Usuario”) = e

MessageBox( item.ToString)

In Desktop:
desktop_test

In Android:
android_test

I use Xojo 2023r3 in Linux Kubuntu 22.04
Thanks in advance

Well, Android is in “beta”, it is expected to have lot of bugs and inconsistencies for a couple years at least.

As for your app, I hope you dont need currency or any decimal values, Json in desktop is also kind of BROKEN. Critical Gap in API and JSON - #22 by MarkusR

behave it same if you change Dictionary to JSONItem?

1 Like

Thanks for reporting.
This is simply broken and I just reported it as issue for you: #74467: Dictionary in JSONItem with Android doesn’t encode well

Perfect! That works! Thank you!

var datos as New JSONItem
datos.Value("usuario") = "edu"
datos.Value("clave") = "123"
var bloque as New JSONItem
bloque.Value("Usuario") = datos

MessageBox(bloque.ToString)

android_ok

1 Like

Greg mentioned in another thread not to mix Dictionary into JSONItem. Bug or not, this seems like very good advice to follow.

I personally recommend that when your input and output are JSON, that you use JSONItem so that your code is clear about what it does.

2 Likes