Showing posts with label Json. Show all posts
Showing posts with label Json. Show all posts

Android JSON Parsing Example.

The process of parsing JSON in Android is pretty simple, thankfully. We'll be using JSONObject for all the parsing goodness - there are also some other JSON classes, but we'll just go through the basic ones to give you a general idea of how it works.

  1. String strJson="your url";  
  2.           
  3.                String data = "";  
  4.                try {  
  5.                      // Create the root JSONObject from the JSON string.  
  6.                    JSONObject  jsonRootObject = new JSONObject(strJson);  
  7.   
  8.                    //Get the instance of JSONArray that contains JSONObjects  
  9.                     JSONArray jsonArray = jsonRootObject.optJSONArray("Employee");  
  10.                      
  11.                     //Iterate the jsonArray and print the info of JSONObjects  
  12.                     for(int i=0; i < jsonArray.length(); i++){  
  13.                         JSONObject jsonObject = jsonArray.getJSONObject(i);  
  14.                            
  15.                         int id = Integer.parseInt(jsonObject.optString("id").toString());  
  16.                         String name = jsonObject.optString("name").toString();  
  17.                         float salary = Float.parseFloat(jsonObject.optString("salary").toString());  
  18.                            
  19.                        }  
  20.                     output.setText(data);  
  21.                  } catch (JSONException e) 
  22.                   {e.printStackTrace();
  23.         }  
  

Select DateRange UsingRangePicker.

  /* * This Method is for select range from picker. * */ private fun selectDateRangeUsingRangePicker () { pageNumber = 1 val displ...