B4J Question Retrieve Json Map in correct order of insertion?

MathiasM

Active Member
Licensed User
Hello

Is there a way to get a Json Map in the order it was put into. It's not really an issue, but for API browsers and documentation it's nicer to return Json results (and errors following RFC 7807) in the order people expect.

Consider this code:
B4X:
Dim m As Map
   m.Initialize
   m.Put("first", "testvalue")
   m.Put("last", "testvalue")
 
    Dim j As JSONGenerator
    j.Initialize(m)
    Log(j.ToPrettyString(4))
Will return this:

{
"last": "testvalue",
"first": "testvalue"
}
I could write a reverse function, but maybe an 'Add' function on a Map instead of 'Put' would be more graceful?

Thanks
 

MathiasM

Active Member
Licensed User
Thanks for that link FrostCodes! Didn't notice that thread!
Altough I seem to be doing something wrong, as it doesn't work for me. See that thread for more details.
 
Top