Android length JSONArray

I have an array from the json channel, I know that there is one league in jArray, but I need to calculate the counter of this array if the second is added to the feed later. currently log cat is not logging out of the "teamFeedStructure" system Does anyone know what I'm doing wrong, or know how to correctly turn the length of an array into a string that I can use in intent?

heres code

JSONObject obj = new JSONObject(json);
JSONObject objData = obj.getJSONObject("data");                      
JSONArray jArray = objData.getJSONArray("structure");
//String leagues = jArray.toString();
//Log.v("myapp", "structure" + leagues);
for (int i=0; i < jArray.length(); i++) {    
     JSONObject oneObject = jArray.getJSONObject(i);
     leaguecountArray = oneObject.getJSONArray("league_id");
     for (int l=0; l < leaguecountArray.length(); l++) {     
         if (leaguecountArray.length() == 1) {
             teamFeedStructure = "One";
         }
         if (leaguecountArray.length() == 2) {
              teamFeedStructure = "Two";
         }
         Log.v("myapp", teamFeedStructure);  
      }
}
+3
source share
3 answers

Why do you need iteration here:

for (int l=0; l < leaguecountArray.length(); l++)
{    
    if (leaguecountArray.length() == 1){

         teamFeedStructure = "One";
    }
    if (leaguecountArray.length() == 2){

        teamFeedStructure = "Two";
    }
    Log.v("myapp", teamFeedStructure);   
 }

Do not pay attention to how many passes you make, the result will still be the same.

You can also use not English words, but Stringby holding down the number you need. Do this:

teamFeedStructure = String.valueOf(leaguecountArray.length());

"2", . : int number = Integer.parseInt(teamFeedStructure);

+1

 teamFeedStructure = "greater two";

 if (leaguecountArray.length() == 1){

, .

0

Thanks for your help to everyone who discovered that I’ve gone too far in the feed, so I didn’t get anything in Logcat. Now he is considered good.

0
source

All Articles