Android Question JSON & Maps

LucaMs

Expert
Licensed User
JSON generator / parser seems to convert maps' keys to string:

B4X:
Dim mapSource As Map
    mapSource.Initialize
    Dim i As Int
    For i = 1 To 3
        mapSource.Put(i,i)
    Next
    Dim jg As JSONGenerator
    jg.Initialize(mapSource)
    Dim sJSON As String = jg.ToString
    
    
    Dim jp As JSONParser
    jp.Initialize(sJSON)
    Dim mapOther As Map = jp.NextObject
    For i = 0 To mapOther.Size - 1
        Log(i & TAB & mapOther.GetKeyAt(i) & TAB & GetType(mapOther.GetKeyAt(i)))
        Log(i & TAB & mapOther.GetValueAt(i) & TAB & GetType(mapOther.GetValueAt(i)))
    Next
log:

0 3 java.lang.String
0 3 java.lang.Integer
1 2 java.lang.String
1 2 java.lang.Integer
2 1 java.lang.String
2 1 java.lang.Integer


Am I doing something wrong or is it so?
 

LucaMs

Expert
Licensed User
What do you want to achieve? For sure there's a solution.
send a map that has integers as keys. I understood that it can not be done; I'll have to convert them to string and vice versa when I receive the map.

Thank you.
 
Top