GIRISH PUROHIT GIRISH PUROHIT - 5 months ago 9
Java Question

in some movie,Description is null then i want to set "not available" there.so how can i do this?

private void getDATA(String json) throws JSONException {


moviename = new ArrayList<>();
Currentmovie c = new Currentmovie();
String story = "About The Story";

JSONArray values = new JSONArray(json);
for(int i = 0; i < values.length(); i++) {
JSONObject jsonObject = values.getJSONObject(i);

String movieTitle = jsonObject.getString("Title");
String disc = jsonObject.getString("Description");
Log.e(TAG,"GIRISH"+movieTitle);
c= new Currentmovie();
c.setTitle("Movie Name::"+movieTitle);
c.setDesc(story+"::\n"+disc);
if(jsonObject.getString("Description")==null)
{

c.setDesc(story+"::Not Available");
}
moviename.add(c);

}


//(disc == null) is also not working,(disc.equalsto(null)) is also not working...
//in some movie,Description is null then i want to set "not available" there.so how can i do this?

Answer

if your json string is:{"Title":"One movie"}

then jsonObject.getString("Description")==null

if your json string is:{"Title":"One movie","Description":""}

then jsonObject.getString("Description").equals("")