Failing to parse json string from a file. "jMap = JSON.NextObject".
B4X:
Application_Start
>>> Login file exists
Error occurred on line: 226 (Main)
Error parsing string: Error Domain=NSCocoaErrorDomain Code=3840 "No string key for value in object around character 1." UserInfo={NSDebugDescription=No string key for value in object around character 1.}
Stack Trace: (
CoreFoundation <redacted> + 148
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation <redacted> + 0
B4i Pushclient -[B4IJSONParser parse] + 220
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
B4i Pushclient +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
B4i Pushclient -[B4IShell runMethod:] + 448
B4i Pushclient -[B4IShell raiseEventImpl:method:args::] + 1260
B4i Pushclient -[B4IShellBI raiseEvent:event:params:] + 1408
B4i Pushclient __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
libdispatch.dylib <redacted> + 24
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 1016
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 2012
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 100
UIKit UIApplicationMain + 236
B4i Pushclient main + 124
libdyld.dylib <redacted> + 4
)
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 " Error parsing string: Error Domain=NSCocoaErrorDomain Code=3840 "No string key for value in object around character 1." UserInfo={NSDebugDescription=No string key for value in object around character 1.}" UserInfo={NSLocalizedDescription= Error parsing string: Error Domain=NSCocoaErrorDomain Code=3840 "No string key for value in object around character 1." UserInfo={NSDebugDescription=No string key for value in object around character 1.}}>
B4X:
Sub JsonToMap(strJSON As String) As Map
' convert a json string to a map
Dim jMap As Map
jMap.Initialize
Dim JSON As JSONParser
JSON.Initialize(strJSON)
jMap = JSON.NextObject '<<<< failing
Return jMap
End Sub
'read
jsonLine = File.ReadString(File.DirDocuments, "file.dat")
'parser.Initialize(jsonLine)
JsonToMap(jsonLine)
'written as:
Dim jsonLine As String
jsonLine = $"{a:""$ & a& _
$"",b:""$ & myUsername & _
$"",c:""$ & myPassword & _
$"",d:""$ & c & _
$"",e:""$ & b & $""}"$
Last edited: