title: how to parse JSON response from server and use it in comparison
body: <p>I want to parse JSON response from server but I m unable to do it. please help me</p>
  
  <p>server response for connection success is  </p>
  
  <pre><code>Database connection success....{"server_response":[{"code":"reg_true","0":"message=&gt;Registration Success...Thank you....."}]}
  </code></pre>
  
  <p>I want to parse it and use server_response and code values in comparing so I can execute IF statement 
  When I debug my code. It shows that json =  Database connection success....{"server_response":[{"code":"reg_true","0":"message=>Registration Success...Thank you....."}]} </p>
  
  <p>but then it jump to catch (JSONException e) 
  please help
  this is my code</p>
  
  <pre><code>        JSONObject jsonObject = new JSONObject(json);
          JSONArray jsonarry= jsonObject.getJSONArray("server_response");
          JSONObject JO = jsonarry.getJSONObject(0);
          String code = JO.getString("code");
          String message = JO.getString("message");
  
          if (code.equals("reg_true")) {
  
              showDialog("Registration Success",code,message);
  
          } else if (code.equals("reg_false")) {
  
  
              showDialog("Registration Failed",code, message);
  
          } else if (code.equals("login_true")) {
              Intent intent = new Intent(activity, HomeActivity.class);
              intent.putExtra("message", message);
              activity.startActivity(intent);
          } else if (code.equals("login_false")) {
              showDialog("Login Error...",code,message);
          }
  
  
      } catch (JSONException e) {
          e.printStackTrace();
      }
  }
     public void showDialog(String title, String code, String message)
     {
  
        builder.setTitle(title);
         if(code.equals("reg_true")||code.equals("reg_false"))
         {
  
             builder.setMessage(message);
             builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int which) {
                     dialog.dismiss();
                     activity.finish();
                 }
  
             });
  </code></pre>