Android Question Retrieve Data Row from Web Service

Discussion in 'Android Questions' started by hendrayulianto, Jun 17, 2015.

  1. hendrayulianto

    hendrayulianto Member Licensed User

  2. eurojam

    eurojam Well-Known Member Licensed User

    You have to make you familar with httpUtils and Json. Then it is not that much to do. I hve made a small example to give you a starting point. My provided example is a bit of dirty hack... you need to examine the response from the webservice....(see this great tool from Erel: http://www.basic4ppc.com:51042/json/index.html)

    The example uses the httpUtils2 and JSON Libs.
    Code:
    Sub Globals
      
    Dim lv As ListView
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        lv.Initialize(
    "lv")
        
    Activity.AddView(lv,0,0,100%x,100%y)
        
    Dim s As String
        
    Dim job1 As HttpJob
        s = 
    "http://www.traveloista.com/traveloista.asmx/GetMail?UserName=eveline@traveloista.com"
        job1.Initialize(
    "Job1", Me)
        job1.Download(s)
    End Sub

    Sub JobDone (Job As HttpJob)
       
    Dim s As String
       
    If Job.Success = True Then
          
    Log("Yeaahh")
          
    Select Job.JobName
             
    Case "Job1"
               s = Job.GetString
               ParsJSON(s)
           
    End Select
      
    Else
         
    Log("Buuuh")
      
    End If      
    End Sub

    Sub ParsJSON (jsonstring As String)
    Log(jsonstring)
    Dim a,b As Int
       a = jsonstring.IndexOf(
    "[")
       b = jsonstring.LastIndexOf(
    "]")
       jsonstring = jsonstring.SubString2(a, b+
    1)

       
    Dim parser As JSONParser

       parser.Initialize(jsonstring)

       
    Dim root As List = parser.NextArray
       
    For Each colroot As Object In root
        
    If colroot Is List Then
        
    Dim l As List
         l = colroot
         
    'show the emails adress in the listview
         lv.AddSingleLine(l.get(0))
        
    End If   
       
    Next   
    End Sub
     
    Erel and DonManfred like this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    (Don't forget to call Job.Release at the end of JobDone)
     
Loading...