Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Read json url in android - NAYCode.com


//*********** For more tutorial visit NAYCode.com

@Override

protected void onPostExecute(String result) {

// TODO Auto-generated method stub

super.onPostExecute(result);

 /****************** Start Parse Response JSON Data *************/

        

        String OutputData = "";

        String UserName="";

        JSONObject jsonResponse;


        try {

               

             /****** Creates a new JSONObject with name/value mappings from the JSON string. ********/

             jsonResponse = new JSONObject(result);

              /***** Returns the value mapped by name if it exists and is a JSONArray. ***/

                 /*******  Returns null otherwise.  *******/

                 JSONArray jsonMainNode = jsonResponse.optJSONArray("clsStatus");


                 /*********** Process each JSON Node ************/

                 int FlgStatus   = 0;

                 int FlgState  = 0;

                 int ColorCode  = 0;

                 String Message   ="";

                 String Card1="";

                 String Card2="";

                 String Card3="";

                 String EmpNo="";

                 String EmpName="";

                 int lengthJsonArr = jsonMainNode.length(); 

                 for(int i=0; i < lengthJsonArr; i++)

                 {

                     /****** Get Object for each JSON node.***********/

                     JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);

                       

                     /******* Fetch node values **********/

                      FlgState= Integer.parseInt( jsonChildNode.optString("FlgState").toString());
                      FlgStatus   = Integer.parseInt( jsonChildNode.optString("FlgStatus").toString());
                      ColorCode = Integer.parseInt( jsonChildNode.optString("ColorCode").toString());
                      Message     = jsonChildNode.optString("Message").toString();
                      UserName = jsonChildNode.optString("UserName").toString();

                      

                      if (FlgState==1)

                      {

                       EmpNo     = jsonChildNode.optString("EmpNo").toString();
                       Card1     = jsonChildNode.optString("CardNo1").toString();
                       Card2     = jsonChildNode.optString("CardNo2").toString();
                       Card3     = jsonChildNode.optString("CardNo3").toString();
                       EmpName = UserName;

                       SaveEmpDetailInDevice(Card1, Card2, Card3, EmpNo, EmpName);

                      }

                }

             /****************** End Parse Response JSON Data *************/   

              EditText txtCardNo=(EditText)findViewById(R.id.edittxtCardNo); 

                 if (FlgStatus==-1) // If Error is founded

                 {

                    lblMessage=(TextView)findViewById(R.id.lblmsg); 
                    lblMessage.setText(Message);
                    txtCardNo.setText("");
                    Refreshtextbox_timer();
                 }

 

             if (FlgStatus==1) // If Error is founded
             {

               lblMessage=(TextView)findViewById(R.id.lblmsg); 
               lblMessage.setText(Message);
              txtCardNo.setText("");

              Refreshtextbox_timer();

                 TextView toastMessage = (TextView) toast.getView().findViewById(android.R.id.message);
                 toastMessage.setTextColor(Color.BLACK);
                 toastMessage.setBackgroundColor(Color.RED);
                 toastMessage.setTextSize(25);
                 toast.show();

                 }


                 if (FlgStatus==2) // If request operation successful

                 {

                   lblMessage=(TextView)findViewById(R.id.lblmsg); 
                   lblMessage.setText(Message);

                 }


                 if (ColorCode==1)

                 {

                   lblMessage=(TextView)findViewById(R.id.lblmsg); 
                   lblMessage.setBackgroundColor(Color.WHITE);
                   lblMessage.setTextColor(Color.BLACK);
                 }


                 if (ColorCode==2)

                 {

                    lblMessage=(TextView)findViewById(R.id.lblmsg); 
                    lblMessage.setBackgroundColor(Color.RED);
                    lblMessage.setTextColor(Color.YELLOW);

                 }


         } catch (JSONException e) {

             e.printStackTrace();

         }

}

}
Comment

PREVIOUS NEXT
Code Example
Java :: Java Access ConcurrentHashMap Elements 
Java :: take a peice from array java 
Java :: close GUI in jvava 
Java :: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message) 
Java :: javaparser 
Java :: creating jdbc connection in java using service name oracle 
Java :: kotlin edittext default value 
Java :: java exception to string 
Java :: refresh sharedpreferences going back java 
Java :: update java windows 
Java :: measure view height android 
Java :: mongodb spring boot index usage 0 
Java :: java nested static class 
Java :: Java Define a Functional Interface in java 
Java :: java interview questions 
Java :: java add two arrays together 
Java :: list of java 
Java :: Java List Remove Elements using remove() method 
Java :: java insertion sort 
Java :: java casting to int 
Java :: what is ioexception in java 
Java :: can we override the overloaded method in java 
Java :: import string java 
Java :: is it possible to declare two conditions in for loop in javascrip 
Java :: Exception handling using try...catch 
Java :: meter to cm 
Java :: java heap example 
Java :: Service vs IntentService. 
Java :: kingkaihockey 
Java :: control flow graph generator 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =