0

I have an array jArray in the format :

{"users":[
           {
                 "user_id":6,
                 "user_name":"Ted Vanderploeg",
                 "email":"[email protected]",
                 "additional_info":[["HP","Chief Sales Officer","","",1]]
            },
            {
                 "user_id":59,
                 "user_name":"Lindsay White",
                 "email":"[email protected]",
                 "additional_info":[["Microsoft","Global Head","","",1]]
             }
          ]
}

Now I need to get the value "Microsoft" from additional_info array. This is what I'm trying :

for(int i=0;i<jArray.length();i++) {

     JSONObject jsonObject = new JSONObject(jArray.getString(i));
     String workInfo = jsonObject.getString("additional_info");
     Log.i("MyActivity", "got work obj as " + workInfo.toString());
}

Now I get workInfo as [["Microsoft","Global Head","","",1]]. Stuck on how to proceed next, to get the value Microsoft.

0

1 Answer 1

1

it looks like a JSONArray inside a JSONArray

for(int i=0;i<jArray.length();i++) {
 JSONObject jsonObject = new JSONObject(jArray.getString(i));
 JSONArray workinfo = jsonObject.optJSONArray("additional_info");
   if (workinfo != null) {
        for(int j=0;j<workinfo.length();j++) {
             JSONArray values = workinfo.optJSONArray(j);
             for(int z=0;z<values.length();z++) {
                  Log.i("MyActivity", "got work obj as " + values.optString(z));
             }
        }
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.