B4J Question Json Parsen Hilfe

ronnhdf

Member
Licensed User
Longtime User
Hallo könnte mir jemand helfen folgenden Json zu parsen

B4X:
{"result":[["23332c4013124b0092568b4514a6b6e6.d",1428959785325,{"plext":{"text":"ickeoch deployed an L1 Resonator on Akzent (Am Steinberg 2, 13086 Berlin, Germany)","markup":[["PLAYER",{"plain":"ickeoch","team":"RESISTANCE"}],["TEXT",{"plain":" deployed an "}],["TEXT",{"plain":"L1"}],["TEXT",{"plain":" Resonator on "}],["PORTAL",{"name":"Akzent ","plain":"Akzent (Am Steinberg 2, 13086 Berlin, Germany)","team":"RESISTANCE","latE6":52556333,"address":"Am Steinberg 2, 13086 Berlin, Germany","lngE6":13429370}]],"plextType":"SYSTEM_BROADCAST","categories":1,"team":"RESISTANCE"}}],["ad8d414fb97c44f88b62c7c8341811e2.d",1428959784873,{"plext":{"text":"bonnt destroyed an L8 Resonator on Jugendclub KoCa (Landsberger Allee 16, 10249 Berlin, Germany)","markup":[["PLAYER",{"plain":"bonnt","team":"ENLIGHTENED"}],["TEXT",{"plain":" destroyed an "}],["TEXT",{"plain":"L8"}],["TEXT",{"plain":" Resonator on "}],["PORTAL",{"name":"Jugendclub KoCa","plain":"Jugendclub KoCa (Landsberger Allee 16, 10249 Berlin, Germany)","team":"RESISTANCE","latE6":52523499,"address":"Landsberger Allee 16, 10249 Berlin, Germany","lngE6":13435741}]],"plextType":"SYSTEM_BROADCAST","categories":1,"team":"ENLIGHTENED"}}]]}

mein Code Aktuell

B4X:
Dim root As Map = parser.NextObject
Dim result As List = root.Get("result")
For Each colresult As List In result
        Dim Guid As String = colresult.Get(0)
        Dim Timstamp As String = colresult.Get(1)
        Dim Plext As List = colresult.Get(2)
        'Dim markup as Map =
       
        'Dim PText As String = Plext.Get("text")
        'Dim text As String
        'Dim Agent As Map
                  Dim m As Map = Plext.Get("plext")
                      Log(m.GetKeyAt(0) & " = " & m.GetValueAt(0)) 
            ' resp.Write(Plext.Values)
    For Each colcolresult As String In colresult
    Next
Next
 

billzhan

Active Member
Licensed User
Longtime User
The json tree example may help:
http://b4x.com:51042/json/index.html

upload_2015-4-14_8-15-7.png
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

try to test with the B4X online parser.

Result (<text> is your string to parse)

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim result As List = root.Get("result")
For Each colresult As List In result
   For Each colcolresult As String In colresult
   Next
Next
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
This json string is complex. If you need every value,you have to iterate manually.

B4X:
    Dim parser As JSONParser
    parser.Initialize(string2parse)
    Dim root As Map = parser.NextObject
    Dim result As List = root.Get("result")
   
    Dim sublist_1 As List=result.Get(0)
    Dim sublist_2 As List=result.Get(1)
    'sublist_1 sublist_2 has similar structure
   
'get values in sublist_1   
    Dim sublist_1_Guid As String = sublist_1.Get(0)
    Dim sublist_1_Timstamp As String = sublist_1.Get(1)
   
    Dim sublist_1_2_map As Map = sublist_1.Get(2)    'it's a map ;not list
    Dim sublist_1_Plext_map As Map=sublist_1_2_map.Get("plext")
   
    Dim sublist_1_text_string As String=sublist_1_Plext_map.Get("text")
    Dim sublist_1_plextType_string As String=sublist_1_Plext_map.Get("plextType")
    Dim sublist_1_categories_string As String=sublist_1_Plext_map.Get("categories")
    Dim sublist_1_team_string As String=sublist_1_Plext_map.Get("team")
    Dim sublist_1_markup_list As List=sublist_1_Plext_map.Get("markup")
    'values in sublist_1_markup_list
   
'get values in sublist_2 ...
 
Upvote 0
Top