0

I am developing an app in which i am calling a service, in which data is coming as an array format. As shown below:

[  
 {  
  "Image":null,
  "FirstName":null,
  "Active":false,
  "HallTicketNumber":0,
  "ReportingTime":null,
  "EventDetails":null,
  "CompanyName":null,
  "Designation_Role":null,
  "EventDate":null,
  "StateName":null,
  "CityName":null,
  "FullAddress":null,
  "HallTicket_Status":"HETSTOP"
 }
]

In that i need to check the condition for HET_STATUS,if that StATUS is HET STOP then it should print that het stop. But when i am trying to check the condition it is showing nothing:

Below is my code:

  String StringData = "" + data;
  try {
          JSONArray rootArray = new JSONArray(StringData);
          int len = rootArray.length();
          for (int i = 0; i < len; ++i) {
               JSONObject json = rootArray.optJSONObject(i);

               String CompanyName = json.optString("CompanyName ");
               String Position = json.optString("Designation_Role");
               String EventDate = json.optString("EventDate");
               String StateName = json.optString("StateName ");
               String CityName = json.optString("CityName");
               String Address = json.getString("FullAddress");
               String ReportingTime = json.getString("ReportingTime");
               String HallTicket_Status = json.getString("HallTicket_Status");

               if (HallTicket_Status == "HETSTOP") {
                   Toast toast = Toast.makeText(UpcomingEventsDetails.this, "HET STOP", Toast.LENGTH_LONG);
                   toast.setGravity(Gravity.CENTER, 0, 0);
                   toast.show();
3
  • 1
    Use HallTicket_Status.equalsIgnoreCase("HETSTOP") Commented Sep 20, 2016 at 11:54
  • Yes ,I got it.Thankyou Commented Sep 20, 2016 at 12:07
  • Np. Wel come !! Commented Sep 20, 2016 at 12:08

2 Answers 2

1

Try this way,

if(HallTicket_Status.equalsIgnoreCase("HETSTOP")){
    Toast toast = Toast.makeText(UpcomingEventsDetails.this, "HET STOP", Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}else{
    //do something
}

boolean equals(String str): Case sensitive comparison

boolean equalsIgnoreCase(String str): Case in-sensitive comparison

== will still test object equality. It is easy to be fooled, however:

Integer a = 10;
Integer b = 10;

System.out.println(a == b); //prints true

Integer c = new Integer(10);
Integer d = new Integer(10);

System.out.println(c == d); //prints false. however:

Integer a = 10;
Integer b = 10;

System.out.println(a == b); //prints true

Integer c = new Integer(10);
Integer d = new Integer(10);

System.out.println(c == d); //prints false
Sign up to request clarification or add additional context in comments.

Comments

0

Don't use == condition for strings. Instead of use str.equals("HEYSTOP") . This will return boolean. If you check string is null then you should use == or != conditions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.