I would like to return a string from an IF statement. Below is the code. I am parsing a JSON object and need to insert the data into a sql lite table.
if (object.has("message")) {
JSONObject message = object.getJSONObject("message");
String newtype_mod = object.getJSONObject("message").getString("type");
String newcontent_mod = object.getJSONObject("message").getString("content");
objSample = new GetSetMethod();
objSample.setnewcontent_mod(newcontent_mod);
objSample.setnewtype_mod(newtype_mod);
Log.v("##" + newcontent_mod, "V " + newtype_mod);
}
objSample = new GetSetMethod();
objSample.setNewreportid(newreportid);
objSample.setnewcontent_mod(newcontent_mod);
objSample.setnewtype_mod(newtype_mod);
Log.v("" + newcontent_mod, "" + newtype_mod);
As you would have understood newcontent_mod and newtype_mod will not be accessible from the IF statement. And I need the IF statement compulsorily.
I understand the question is basic. Please help a fellow newbie !
Thanks!
You can declare it outside the if statement and just assign the value to these variables
for example:
otherwise
You can declare both at Global level i.e. class level variables