B4J Library json-simple2(keep the json order)

icefairy333

Active Member
Licensed User
usage same as JSONGenerator
B4X:
Private jsg2 as JSONGenerator2
Dim ret As Map
    ret.Initialize
    If success Then ret.Put("code",200) Else ret.Put("code",500)
    ret.Put("data",data)
    jsg2.Initialize(ret)
    res.Write(jsg2.ToString)
2017-7-12 13:01:39
v1.1 add jsonparser(the functions are same as jsonparser in b4x)
 

Attachments

Last edited:

MathiasM

Active Member
Licensed User
Thanks for you library, altough I doesn't seem to work for me.
I have this code:
B4X:
Dim ErrorMap As Map
   ErrorMap.Initialize
   ErrorMap.Put("type","http://linktobereplaced.com/probs/login-failed")
   ErrorMap.Put("detail", "You provided wrong credentials.")
   ErrorMap.Put("instance", mRequest.RequestURI)
   
   Dim jsonError As JSONGenerator2
   jsonError.Initialize(ErrorMap)
And this returns:

{"detail":"You provided wrong credentials.","instance":"/authentication","type":"http://linktobereplaced.com/probs/login-failed"}
 

mcqueccu

Active Member
Licensed User
In this instance the order was preserved

B4X:
Dim m As Map
    m.Initialize
    For i = 1 To 10
        m.Put(i, i)       
    Next
    Log(m)
    Dim jg As JSONGenerator2
    jg.Initialize(m)
    Log(jg.ToString)
OUTPUT
B4X:
(MyMap) {1=1, 2=2, 3=3, 4=4, 5=5, 6=6, 7=7, 8=8, 9=9, 10=10}
{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10}
 
Top