B4J Question Json Parsen Hilfe

Discussion in 'B4J Questions' started by ronnhdf, Apr 13, 2015.

  1. ronnhdf

    ronnhdf Member Licensed User

    Hallo könnte mir jemand helfen folgenden Json zu parsen

    Code:
    {"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

    Code:
    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
     
  2. billzhan

    billzhan Active Member Licensed User

  3. ronnhdf

    ronnhdf Member Licensed User

    komme aber leider nicht über das Array Plext hinaus
     
  4. billzhan

    billzhan Active Member Licensed User

    which value(s) do you want to get?
     
    Last edited: Apr 14, 2015
  5. ronnhdf

    ronnhdf Member Licensed User

    all value
     
  6. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    try to test with the B4X online parser.

    Result (<text> is your string to parse)

    Code:
    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
     
  7. billzhan

    billzhan Active Member Licensed User

    This json string is complex. If you need every value,you have to iterate manually.

    Code:
    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 ...
     
    ronnhdf likes this.
  8. ronnhdf

    ronnhdf Member Licensed User

    Thank you!!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice