Android Question Map with integer keys comes back reordered and with string keys after WriteMap/ReadMap

tonykkkkk

Member
Licensed User
Longtime User
Sub OneForTheForum
Dim btns As Map
btns.Initialize
btns.Put(1, "aaa")
btns.Put(2, "bbb")
Log(btns.Get(1))
Log(btns.Get(2))
File.WriteMap(File.DirInternal, "xxx", btns)
Dim getemback As Map
getemback = File.ReadMap(File.DirInternal, "xxx")
For Each i As Int In getemback .Keys
Log(getemback.Get(i))
Next
For Each i As Int In getemback .Keys
Log(getemback.Get(i & ""))
Next
End Sub

The log shows
aaa
bbb
null
null
bbb
aaa

So there may be a second issue: this is a B4A project and "Map Collection - The most useful collection..." says order should be preserved
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Please use [code]code here...[/code] tags when posting code.
2. It is not a bug. Read the documentation of File.WriteMap and File.ReadMap.

1629015055683.png


You should use B4XSerializator or KeyValueStore instead.
 
Upvote 0
Top