My app fetches JSON data from a server and stores them in a CardView. All the data is processed correctly, but if some data isn't available at the moment the JSONArray is empty. The app fetches them anyway and writes 'null' into the TextView, while I want to have it empty. I already searched other related questions and thought it was the best way to check the length of the array, but still it puts 'null' in my TextView:
What I get:
(null - null)
What I want to have:
( - )
This is the structure of what is fetched:
[
{
"MatchResults": []
}
]
How I tried to handle it:
JSONArray jArray = json.getJSONArray("MatchResults");
for(int j=0; j<jArray.length(); j++) {
JSONObject json_data = jArray.getJSONObject(j);
if(jArray != null && jArray.length() > 0){
GetDataAdapter.setTore1(json_data.getString(TEAM1));
GetDataAdapter.setTore2(json_data.getString(TEAM2));
}
}
What do I have to change so that the setTore1 and setTore2 method leave the TextView empty?
MatchResultsarray is empty. Or is it not the data you are working with? In that case provide an actual example.