How to Json Parsing in android

前端 未结 4 1917
遇见更好的自我
遇见更好的自我 2021-01-07 08:18

http://docs.blackberry.com/sampledata.json

This is my web service and I want to parse and retrieve vehicleType, vehicleColor, fuel, name, experiencePoints, treadType

4条回答
  •  -上瘾入骨i
    2021-01-07 08:34

    try{
     HttpGet request = new HttpGet(loginUrl);
     HttpResponse response = httpClient.execute(request);
     entityResponse = response.getEntity();
     result = EntityUtils.toString(entityResponse);  
    
    
    JSONArray array = object.getJSONArray("routes"); 
    
    
    ---Parsing first jsonArray     
      JSONObject routes = array.getJSONObject(0);
    
    
    ---(parsing first jsonarray object)
      String bounds= routes.getString("bounds"); 
    
    
    -- parsing second josn Array  
      JSONArray legs = routes.getJSONArray("legs"); 
    
    
    --- (parsing second jsonarray object)   
    
    JSONObject steps = legs.getJSONObject(0); 
    
    String distance= routes.getString("distance"); 
    
    
    --- parsing third json Array
      JSONArray legs1 = steps.getJSONArray("steps"); 
      for(int i = 0; i < legs1.length(); i++){
      JSONObject steps1 = legs1.getJSONObject(i);
    
    
    --parsing third jsonarray objecct      
      String htMlVale = steps1.getString("html_instructions").toString(); 
    
    
    -- parsing inside third jsonarray of jsonarray   
      JSONObject distance             =  steps1.getJSONObject("distance");
              String sDistance                =  distance.getString("text");()
    
    
    
            }
    } 
    

提交回复
热议问题