iOS Question JSON text did not start with array or object

Alexander Stolte

Expert
Licensed User
Longtime User
Hello,

i'm using the JSONGenerator to generate a json string from a list of maps.
Example:
B4X:
    Dim lst As List
    lst.Initialize
    For i = 0 To 5 -1
        lst.Add(CreateMap("timestamp":DateTime.Now,"text":"test" & i))
    Next
    Dim jg As JSONGenerator
    jg.Initialize2(lst)
    Log(jg.ToPrettyString(2))

i received the following crash report from a user:
B4X:
*** Terminating app due to uncaught exception '', reason: 'Error parsing string: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0., NSJSONSerializationErrorIndex=0}'

I found a solution on stackoverflow:
but don't know how to use it with the json generator

Unfortunately I cannot reproduce the error, I have used all the special characters my keyboard has to offer, I have even created json strings, but nothing causes a crash.

Am I missing something? I would be grateful for any advice, thanks
Alex
 

Alexander Stolte

Expert
Licensed User
Longtime User
The problem is somewhere else
You're right, I was confused by the log file. I then realized that I use AddPageAndCreate and it then fetches the feature request list from supabase at every application start, where I use the json parser. The user who reported this to me is from china, it is possible that he does not have access to my supabase server and therefore does not get a json string back.

Thanks for the answer, without it I would have been looking in the wrong place.
 
Upvote 0
Top