Domanda

I'm working on one app in which I have JSON Like..

    {
    "Group Details":
    [
        {
        "groupMasterId": "25",
        "GroupName": "Gangs of Beasts",
        "groupIcon": "http://xxx.xxx.xx.x/XYZ/images/evil.png",
        "GroupDescription": "Fellowzzzgroup",
        "GroupCreatedDate": "2014-04-30 15:41:01",
        "GroupMassage": "no such thing is like group msg",
        "UserData":
            [
            {"UserMobile": "1111111111","AdminFlag": "1"},
            {"UserMobile": "1234567890","AdminFlag": "0"},
            {"UserMobile": "9988776655","AdminFlag": "0"},
            {"UserMobile": "234t537535","AdminFlag": "0"},
            {"UserMobile": "3489869348","AdminFlag": "0"},
            {"UserMobile": "1234567890","AdminFlag": "0"}
            ]
        }
    ]
}

I want to display Details on simple TextView and UserData in ListView..but the proble in I'm total confused with how to store this data.. I done following code to do it,,but not able to store all UserMobile in single HashMap...

JSONObject jsonObj = new JSONObject(jsonstr);
            GroupDetailsArray = jsonObj.getJSONArray(GROUPDETAILS);
            HashMap<String, String> groupuser = new HashMap<String, String>();
            for (int i = 0; i < GroupDetailsArray.length(); i++) {
                JSONObject l = GroupDetailsArray.getJSONObject(i);
                // String ID= l.getString(GROUPMASTERID);
                String NAME = l.getString(GROUPNAME);
                String DESCRIPTION = l.getString(GROUPDESCRIPTION);
                String DATE = l.getString(GROUPCREATEDDATE);
                String ICON = l.getString(GROUPICON);
                JSONArray UsedDataArray = l.getJSONArray(USERDATA);
                String ADMIN;
                for (int j = 0; j < UsedDataArray.length(); j++) {

                    JSONObject l1 = UsedDataArray.getJSONObject(j);
                    if (l1 != null) {
                        String MOBILENUMBER = l1.getString(USERMOBILE);

                        if (l1.getString(ADMINFLAG).equals("0")) {
                            ADMIN = "Member";
                        } else {
                            ADMIN = "Admin";
                        }
                        // tmp hashmap for single group
                        groupuser.put(USERMOBILE, MOBILENUMBER);
                        groupuser.put(ADMINFLAG, ADMIN);
                    }
                }
                // tmp hashmap for single group
                HashMap<String, String> group = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                group.put(GROUPNAME, NAME);
                group.put(GROUPDESCRIPTION, DESCRIPTION);
                group.put(GROUPCREATEDDATE, DATE);
                group.put(USERDATA, groupuser.toString());
                group.put(GROUPICON, ICON);
                // adding group to group list
                Utility.groupdetailsarraylist.add(group);
                Log.d("groupdetailsarraylist",
                        Utility.groupdetailsarraylist.toString());
            }

please help me to how to store data so that I can use it to store in next Activity...

È stato utile?

Soluzione

       List list1=new ArrayList<String>();
    JSONArray array=jso.getJSONArray("UserData");
    for(int i=0;i<array.length();i++)
    {                                   list1.add(array.getJSONObject(i).getString("UserMobile"));

    }
   Iterator itr=list1.iterator();
     while(itr.hasNext())
    {
        str1=itr.next().e+"\n";

    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top