iOS Question JSON error

Alberto SN

Member
Licensed User
Hi!

I got a JSON received from my server.

This is the code from reception:

B4X:
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim root As Map = parser.NextObject
Dim id As String = root.Get("ID")
Dim description As List = root.Get("description")
Dim waypoints As List = root.Get("waypoints")
For Each colwaypoints As Map In waypoints
    Dim idw As String = colwaypoints.Get("ID")
    Dim postTitlew As String = colwaypoints.Get("post_title")
Next

This is Job.GetString value:

(read only map) {
ID = t1;
description = "Questa \U00e8 una descrizione cortissima";
waypoints = (
"(read only map) {\n ID = 1;\n latitudine = \"41.8986108\";\n longitudine = \"12.4768729\";\n \"post_title\" = Pantheon;\n premium = 1;\n}",
"(read only map) {\n ID = 12;\n latitudine = \"41.8913541\";\n longitudine = \"12.4768729\";\n \"post_title\" = Colosseo;\n premium = 0;\n}"
);
},
(......

When arrive to line Dim id As String = root.Get("ID") in line 410, I received this error message:

B4X:
Error occurred on line: 410 (Main)
Method not found: Get:, target: (
    "(read only map) {\n    ID = t1;\n    description = \"Questa \\U00e8 una descrizione cortissima\";\n    lunghezza = 50000;\n    path = \"qiv~F}}ckArAIjBCpCAf@EbACvADAL?JLAfEY~BEhA@J@@ADSjB`@PBVN`@kA|@cCROzA_@|AYRXHKb@h@`@f@^`@AFw@|BU|A\";\n    \"post_modified\" = ver5;\n    \"post_title\" = \"Tour Lunghissimo\";\n    time = 1200;\n    waypoints =     (\n        \"(read only map) {\\n    ID = 1;\\n    latitudine = \\\"41.8986108\\\";\\n    longitudine = \\\"12.4768729\\\";\\n    \\\"post_title\\\" = Pantheon;\\n    premium = 1;\\n}\",\n        \"(read only map) {\\n    ID = 12;\\n    latitudine = \\\"41.8913541\\\";\\n    longitudine = \\\"12.4768729\\\";\\n    \\\"post_title\\\" = Colosseo;\\n    premium = 0;\\n}\"\n    );\n}",
    "(read only map) {\n    ID = t2;\n    description = \"Questa \\U00e8 una descrizione di prova\";\n    lunghezza = 20000;\n    path = \"cqt~FyrfkAVr@lD~@dDz@~NjC@HLv@Db@cCjFoIlRyBrEmDpG_@bAe@~AUHGL[PeA`@{DfARvB?NDh@?N?V]\\\\eApA]r@b@h@`@f@^`@AFw@|BU|A\";\n    \"post_modified\" = ver5;\n    \"post_title\" = \"Tour di prova\";\n    time = 23500;\n    waypoints =     (\n        \"(read only map) {\\n    ID = 132;\\n    latitudine = \\\"41.889818\\\";\\n    longitudine = \\\"12.490685\\\";\\n    \\\"post_title\\\" = \\\"Arco di Costantino\\\";\\n    premium = 0;\\n}\",\n        \"(read only map) {\\n    ID = 12;\\n    latitudine = \\\"41.8913541\\\";\\n    longitudine = \\\"12.4768729\\\";\\n    \\\"post_title\\\" = Colosseo;\\n    premium = 0;\\n}\"\n    );\n}",
    "(read only map) {\n    ID = t3;\n    description = \"Questa \\U00e8 una descrizione incredibile\";\n    lunghezza = 2;\n    path = \"cqt~FyrfkAe@sAUNSHk@HYA]GOGWWW]MU_@|Be@SIn@Kb@Ux@uDvHk@`ByA~C{AbD_GjMk@~@c@b@}@fA_@dCe@Ci@L]LYZg@x@Oj@AVBVCNt@jHqARETERYl@UXSJg@J{@DXxAD\\\\?XUl@Oj@QzA?vAuA@cDVGRANAvANNz@Hr@?r@AdDHhFHd@}BBa@@OLAfEY~BEhA@J@@??ADSjB`@PBVN`@kA|@cCROzA_@|AYRXHKb@h@`@f@^`@AFw@|BU|A\";\n    \"post_modified\" = ver5;\n    \"post_title\" = \"Tour senza compromessi\";\n    time = 5000000;\n    waypoints =     (\n        \"(read only map) {\\n    ID = 132;\\n    latitudine = \\\"41.889818\\\";\\n    longitudine = \\\"12.490685\\\";\\n    \\\"post_title\\\" = \\\"Arco di Costantino\\\";\\n    premium = 0;\\n}\",\n        \"(read only map) {\\n    ID = 1;\\n    latitudine = \\\"41.8986108\\\";\\n    longitudine = \\\"12.4768729\\\";\\n    \\\"post_title\\\" = Pantheon;\\n    premium = 1;\\n}\",\n        \"(read only map) {\\n    ID = 12;\\n    latitudine = \\\"41.8913541\\\";\\n    longitudine = \\\"12.4768729\\\";\\n    \\\"post_title\\\" = Colosseo;\\n    premium = 0;\\n}\"\n    );\n}"
)
Stack Trace: (
  CoreFoundation       __exceptionPreprocess + 182
  libobjc.A.dylib      objc_exception_throw + 44
  CoreFoundation       +[NSException raise:format:] + 141
  Mapsoo               +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 451
  Mapsoo               -[B4IShell runMethod:] + 515
  Mapsoo               -[B4IShell raiseEventImpl:method:args::] + 1888
  Mapsoo               -[B4IShellBI raiseEvent:event:params:] + 1518
  Mapsoo               +[B4IDebug delegate:::] + 79
  Mapsoo               -[b4i_main _jobdone:] + 352
  CoreFoundation       __invoking___ + 29
CoreFoundation       -[NSInvocation invoke] + 360
Mapsoo               +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 2069
Mapsoo               -[B4ICommon CallSubDebug4::::] + 894
Mapsoo               -[B4ICommon CallSubDebug2::::] + 350
Mapsoo               -[b4i_httpjob _complete::] + 887
Mapsoo               -[b4i_httputils2service _completejob::::] + 1585
Mapsoo               -[b4i_httputils2service _hc_responsesuccess::] + 938
CoreFoundation       __invoking___ + 29
CoreFoundation       -[NSInvocation invoke] + 360
Mapsoo               +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 2069
Mapsoo               -[B4IShell runMethod:] + 515
Mapsoo               -[B4IShell raiseEventImpl:method:args::] + 2519
Mapsoo               -[B4IShellBI raiseEvent:event:params:] + 1518
Mapsoo               __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 273
libdispatch.dylib    _dispatch_client_callout + 14
libdispatch.dylib    _dispatch_barrier_sync_f_slow_invoke + 54
libdispatch.dylib    _dispatch_client_callout + 14
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 677
CoreFoundation       __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
CoreFoundation       __CFRunLoopRun + 2256
CoreFoundation       CFRunLoopRunSpecific + 443
CoreFoundation       CFRunLoopRunInMode + 123
GraphicsServices     GSEventRunModal + 192
GraphicsServices     GSEventRun + 104
UIKit                UIApplicationMain + 1526
Mapsoo               main + 138
libdyld.dylib        start + 1
)

Anybody know which is the problem?

Thanks
 

Alberto SN

Member
Licensed User
Hi Erel!

Excuse me, the job return this JSON:

B4X:
JobName = Job1, Success = true
[
    {
        "ID":"t1",
        "post_title":"Tour Lunghissimo",
        "description":"Questa è una descrizione cortissima",
        "time":1200,
        "lunghezza":50000,
        "post_modified":"ver5",
        "path":"qiv~F}}ckArAIjBCpCAf@EbACvADAL?JLAfEY~BEhA@J@@ADSjB`@PBVN`@kA|@cCROzA_@|AYRXHKb@h@`@f@^`@AFw@|BU|A",
        "waypoints":[
            {
                "ID":1,
                "post_title":"Pantheon",
                "premium":"1",
                "longitudine":"12.4768729",
                "latitudine":"41.8986108"
            },        
            {
                "ID":12,
                "post_title":"Colosseo",
                "premium":"0",
                "longitudine":"12.4768729",
                "latitudine":"41.8913541"
            }
        ]
    },
    {
        "ID":"t2",
        "post_title":"Tour di prova",
        "description":"Questa è una descrizione di prova",
        "post_modified":"ver5",
                "time":23500,
        "lunghezza":20000,
        "path":"cqt~FyrfkAVr@lD~@dDz@~NjC@HLv@Db@cCjFoIlRyBrEmDpG_@bAe@~AUHGL[PeA`@{DfARvB?NDh@?N?V]\\eApA]r@b@h@`@f@^`@AFw@|BU|A",
        "waypoints":[
            {
                "ID":132,
                "post_title":"Arco di Costantino",
                "premium":"0",
                "longitudine":"12.490685",
                "latitudine":"41.889818"
            },        
            {
                "ID":12,
                "post_title":"Colosseo",
                "premium":"0",
                "longitudine":"12.4768729",
                "latitudine":"41.8913541"
            }
        ]
    },
    {
        "ID":"t3",
        "post_title":"Tour senza compromessi",
        "description":"Questa è una descrizione incredibile",
        "post_modified":"ver5",
        "time":5000000,
               "lunghezza":2,
"path":"cqt~FyrfkAe@sAUNSHk@HYA]GOGWWW]MU_@|Be@SIn@Kb@Ux@uDvHk@`ByA~C{AbD_GjMk@~@c@b@}@fA_@dCe@Ci@L]LYZg@x@Oj@AVBVCNt@jHqARETERYl@UXSJg@J{@DXxAD\\?XUl@Oj@QzA?vAuA@cDVGRANAvANNz@Hr@?r@AdDHhFHd@}BBa@@OLAfEY~BEhA@J@@??ADSjB`@PBVN`@kA|@cCROzA_@|AYRXHKb@h@`@f@^`@AFw@|BU|A",
        "waypoints":[
            {
                "ID":132,
                "post_title":"Arco di Costantino",
                "premium":"0",
                "longitudine":"12.490685",
                "latitudine":"41.889818"
            },
            {
                "ID":1,
                "post_title":"Pantheon",
                "premium":"1",
                "longitudine":"12.4768729",
                "latitudine":"41.8986108"
            },
            {
                "ID":12,
                "post_title":"Colosseo",
                "premium":"0",
                "longitudine":"12.4768729",
                "latitudine":"41.8913541"
            }
        ]
    }
]

After the reception I convert to map the JSON.

This is the complete code:

B4X:
Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job1"
                Log(Job.GetString2("Windows-1252"))

                sJSONMap = JsonToMap(Job.GetString2("Windows-1252"))
                Dim parser As JSONParser
                parser.Initialize(Job.GetString)
                Dim root As Map = parser.NextObject
                Dim id As String = root.Get("ID")
                Dim postTitle As List = root.Get("post_title")
                Dim description As List = root.Get("description")
                Dim postModified As List = root.Get("post_modified")
                Dim time As List = root.Get("time")
                Dim waypoints As List = root.Get("waypoints")
                For Each colwaypoints As Map In waypoints
                   Dim idw As String = colwaypoints.Get("ID")
                   Dim postTitlew As String = colwaypoints.Get("post_title")
                Next
              
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        hd.ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Thanks
 
Upvote 0
Top