0

I am just parsing one JSON file in Android and my JSON is not consistent, meaning that some attributes and values are missing so I get null pointer exception. I have understood that we should check before extracting value of each attribute if he actually exists:

JSONObject object = jsonArray.getJSONObject(i);
if(!object.isNull("name"))
   String name = object.getString("name");

Since I have 12 parameters to extract the code does not looks nice.

Is there any more elegant solution?

Cœur
  • 37,241
  • 25
  • 195
  • 267
junior
  • 45
  • 1
  • 11

0 Answers0