nibbo Active Member Licensed User Longtime User Sep 11, 2018 #1 Hi All I use a webservice to return JSON data which looks something like: Code: Copy Data:[{"col1":"value1","col2":"value2","col3":"value3","col4","value4"}{…etc...}] I store save the above to the list: Code: Copy dim recordList = root.Get("Data") I then iterate through the list using: Code: Copy For i = 0 To recordList.Size - 1 Dim m As Map = recordList.Get(i) For Each k As String In m.Keys Log(k) Next Next But the order of the keys does not match the order in the JSON, in the example I am running it returns col1, col4, col2 , col3. Is that just how it works or should it retain the correct sequence? I am sure it was in the correct order when I first wrote and tested the code! Thanks Last edited: Sep 11, 2018
Hi All I use a webservice to return JSON data which looks something like: Code: Copy Data:[{"col1":"value1","col2":"value2","col3":"value3","col4","value4"}{…etc...}] I store save the above to the list: Code: Copy dim recordList = root.Get("Data") I then iterate through the list using: Code: Copy For i = 0 To recordList.Size - 1 Dim m As Map = recordList.Get(i) For Each k As String In m.Keys Log(k) Next Next But the order of the keys does not match the order in the JSON, in the example I am running it returns col1, col4, col2 , col3. Is that just how it works or should it retain the correct sequence? I am sure it was in the correct order when I first wrote and tested the code! Thanks
mangojack Expert Licensed User Longtime User Sep 11, 2018 #2 In most cases the order of items in Maps is not important. The order is lost in the native JSON parser implementation. If the order is important you need to use an array ([]) instead of a key/value object ({}). Click to expand... https://www.b4x.com/android/forum/threads/server-online-json-tree-example.39048/#post-259109 Upvote 0
In most cases the order of items in Maps is not important. The order is lost in the native JSON parser implementation. If the order is important you need to use an array ([]) instead of a key/value object ({}). Click to expand... https://www.b4x.com/android/forum/threads/server-online-json-tree-example.39048/#post-259109