iOS Question Problem parsing json

Jack Cole

Active Member
Licensed User
I'm having trouble with a map created from a parsed JSON string. See the code below.

'executed from javascript
Sub ShowSleepLog(Record As String, LastEntryRecord As String)

#if b4i
    Dim su As StringUtils
#end if
    LogColor("Last entry: "&LastEntryRecord,0xFF8300FF)
    'parse out the last entry record if there is one
    If LastEntryRecord.Length>0 Then
        Dim j As JSONParser
        j.Initialize(LastEntryRecord)  '
        Dim m As Map = j.NextObject
'        m.Remove("entered")
        Log("m.ContainsKey" & m.ContainsKey("entered"))
    End If
End Sub
Here is the value for LastEntryRecord.
After trying to remove the "entered" key, it is still there. If I copy the string from the log and put it directly into the code where LastEntryRecord is used to initialize the parser, it works. Any ideas?
Last edited:


Licensed User
After trying to remove the "entered" key, it is still there.
i guess it is because j.NextObject returns a readonly map.

Create a map manually, copy all keys from the NextObject returned Map to the new map.
Delete the key you want from this map.

    Dim fmap As Map ' create a writeable map
    fmap.Initialize ' initialize it
    Dim j As JSONParser
    Dim m As Map = j.NextObject
    '        m.Remove("entered")
    For Each k As Object In m.Keys ' copy all keys to the manually created map fmap
    Log("fmap.ContainsKey" & fmap.ContainsKey("entered")) ' entered exists
    fmap.Remove("entered") ' remove entered
    Log(fmap.ContainsKey("entered")) ' entered does not exists anymore
Ps: Tested on B4J but i expect it works the same in b4i. Don´t know as i do not use b4i

Jack Cole

Active Member
Licensed User
Will try that, but it worked fine for me when I used the string directly in the initialize method (like you did above). The problem comes in when the variable is used. B4A works fine for removing the key, so it doesn't seem to be read only.