Android Question download json file and put into map

sdixon

Member
Licensed User
Longtime User
The JSON file is properly downloaded - verified by log(j.GetString)
When I log the MAP it gives the proper values, but the Map I passed to the sub is empty when I query it later.
How would I get the value of the Map back into general usage?

B4X:
DownloadJSON(f.AgentsMap, f.msFileAgents)

B4X:
Sub DownloadJSON(M As Map, Link As String)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Link)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        Dim JSON As JSONParser
        JSON.Initialize(j.GetString)
        M = JSON.NextObject
        Log(M)
    End If
    j.Release
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
but the Map I passed to the sub is empty when I query it later.
Upload a small example which shows the issue.

You are replacing the map with the result of j.getstring. Probably an empty map in this moment,

You should download the data, create a new map based on the json and then iterate through this map and add all values to the map M
 
Upvote 0

sdixon

Member
Licensed User
Longtime User
B4X:
(MyMap) {}
Upload a small example which shows the issue.

You are replacing the map with the result of j.getstring. Probably an empty map in this moment,

You should download the data, create a new map based on the json and then iterate through this map and add all values to the map M

This seems to have done it

B4X:
For Each key As Object In m1.keys
            M.put(key, m1.get(key))
        Next

Thanks for your help
 
Upvote 0
Top