the Response From Server is:
{"message":"Login successfull","error":false,"user":"{\"DISTRICT\":[{\"Id\":1,\"Name\":\"Abbottabad\"},{\"Id\":3,\"Name\":\"Bannu\"},{\"Id\":4,\"Name\":\"DI Khan\"},{\"Id\":5,\"Name\":\"Kohat\"},{\"Id\":6,\"Name\":\"Mardan\"},{\"Id\":7,\"Name\":\"Peshawar\"},{\"Id\":8,\"Name\":\"Swat\"},{\"Id\":9,\"Name\":\"Battagram\"},{\"Id\":10,\"Name\":\"Buner\"},{\"Id\":11,\"Name\":\"Chitral\"},{\"Id\":12,\"Name\":\"Charsadda\"},{\"Id\":13,\"Name\":\"Dera Ismail Khan\"},{\"Id\":14,\"Name\":\"Hangu\"},{\"Id\":15,\"Name\":\"Haripur\"},{\"Id\":16,\"Name\":\"Karak\"},{\"Id\":17,\"Name\":\"Kolai Pallas Kohistan\"},{\"Id\":18,\"Name\":\"Upper Kohistan\"},{\"Id\":19,\"Name\":\"Lower Kohistan\"},{\"Id\":20,\"Name\":\"Lakki Marwat\"},{\"Id\":21,\"Name\":\"Lower Dir\"},{\"Id\":22,\"Name\":\"Malakand\"},{\"Id\":23,\"Name\":\"Mansehra\"},{\"Id\":24,\"Name\":\"Nowshera\"},{\"Id\":25,\"Name\":\"Shangla\"},{\"Id\":26,\"Name\":\"Swabi\"},{\"Id\":27,\"Name\":\"Tank\"},{\"Id\":28,\"Name\":\"Upper Dir\"},{\"Id\":29,\"Name\":\"Torghar\"}],\"BUSINESS_TYPE\":[{\"Id\":1,\"Name\":\"Hotels\"},{\"Id\":2,\"Name\":\"Restaurants\"},{\"Id\":3,\"Name\":\"Schools\\\/Colleges\"},{\"Id\":4,\"Name\":\"Dhaba\\\/Tea Stall\\\/Shwarma\\\/Dahi Bhalay\"},{\"Id\":5,\"Name\":\"Tandoor\"},{\"Id\":6,\"Name\":\"Juice Shop\"},{\"Id\":7,\"Name\":\"Kabab Shop\"},{\"Id\":8,\"Name\":\"Mega Marts\\\/Super Store\"},{\"Id\":9,\"Name\":\"Stores\"},{\"Id\":10,\"Name\":\"Karyana Store\"},{\"Id\":11,\"Name\":\"Fruits\\\/Dry Fruits\\\/Vegetables\"},{\"Id\":12,\"Name\":\"Meat Shop\"},{\"Id\":13,\"Name\":\"Poultry\\\/Fish Shop\"},{\"Id\":14,\"Name\":\"Whole Sale Dealer\"},{\"Id\":15,\"Name\":\"Distribution Point\"},{\"Id\":16,\"Name\":\"Wharehouse\"},{\"Id\":17,\"Name\":\"Bakers and Confectioners\"},{\"Id\":18,\"Name\":\"Small Industry\"},{\"Id\":19,\"Name\":\"Medium Industry\"},{\"Id\":20,\"Name\":\"Large Industry\"},{\"Id\":21,\"Name\":\"Cottage Industry\"},{\"Id\":22,\"Name\":\"Cart\"},{\"Id\":23,\"Name\":\"Cold Storage\"},{\"Id\":24,\"Name\":\"Slaughter House\"},{\"Id\":25,\"Name\":\"Dairy Shop and Form\"},{\"Id\":26,\"Name\":\"Canteen\"},{\"Id\":27,\"Name\":\"Others\"},{\"Id\":28,\"Name\":\"Oil\\\/Ghee Industry\"},{\"Id\":29,\"Name\":\"Ice Factory\"},{\"Id\":30,\"Name\":\"Salt and Minerals\"},{\"Id\":31,\"Name\":\"Ice Cream Factory\"},{\"Id\":32,\"Name\":\"Water Purification Plant\"},{\"Id\":33,\"Name\":\"Masala\"},{\"Id\":34,\"Name\":\"Papar Factory\"},{\"Id\":35,\"Name\":\"Papar\\\/Chips\\\/Pops Factory\"}],\"ASSISTANT_DIRECTOR\":[{\"staff_id\":1,\"staff_name\":\"Sajjad Ahmad\"},{\"staff_id\":2,\"staff_name\":\"Murad Ali\"}],\"FSO\":[{\"staff_id\":35,\"staff_name\":\"Shahab\"},{\"staff_id\":36,\"staff_name\":\"Shakeel Ahmad Khan\"},{\"staff_id\":37,\"staff_name\":\"Nawab Ali\"},{\"staff_id\":38,\"staff_name\":\"Shakeel Ahmed\"}],\"OFFENCE\":[{\"Id\":1,\"Name\":\"Adultration\"},{\"Id\":2,\"Name\":\"Mislabeling\\\/Misbranding\"},{\"Id\":4,\"Name\":\"Unhygienic Condition\"},{\"Id\":5,\"Name\":\"Banned Items\"},{\"Id\":6,\"Name\":\"Expired Items\"}],\"SAMPLE_DISCARDED\":[{\"Id\":1,\"Name\":\"Milk\"},{\"Id\":2,\"Name\":\"Meat\"},{\"Id\":3,\"Name\":\"Water\"},{\"Id\":4,\"Name\":\"Beverages\"},{\"Id\":5,\"Name\":\"Diary Products\"},{\"Id\":6,\"Name\":\"Poultry\"},{\"Id\":7,\"Name\":\"Salt\"},{\"Id\":8,\"Name\":\"Spices\\\/Masala\"},{\"Id\":9,\"Name\":\"Bakary\"},{\"Id\":11,\"Name\":\"Chips\\\/Pops\"},{\"Id\":12,\"Name\":\"Oil\\\/Ghee\"},{\"Id\":13,\"Name\":\"Ice\"},{\"Id\":14,\"Name\":\"Non-Food Colors\\\/Flavours\"},{\"Id\":15,\"Name\":\"Fruit Pulp\\\/Squash\\\/Jams\\\/Pickles\"}]}"}
What I am trying to do is:
JSONObject obj = new JSONObject(s);
JSONObject userJson = obj.getJSONObject("user");
which Give the Correct Result with Exception which is:
W/System.err: org.json.JSONException: Value {"DISTRICT":[{"Id":1,"Name":"Abbottabad"},{"Id":3,"Name":"Bannu"},{"Id":4,"Name":"DI Khan"},{"Id":5,"Name":"Kohat"},{"Id":6,"Name":"Mardan"},{"Id":7,"Name":"Peshawar"},{"Id":8,"Name":"Swat"},{"Id":9,"Name":"Battagram"},{"Id":10,"Name":"Buner"},{"Id":11,"Name":"Chitral"},{"Id":12,"Name":"Charsadda"},{"Id":13,"Name":"Dera Ismail Khan"},{"Id":14,"Name":"Hangu"},{"Id":15,"Name":"Haripur"},{"Id":16,"Name":"Karak"},{"Id":17,"Name":"Kolai Pallas Kohistan"},{"Id":18,"Name":"Upper Kohistan"},{"Id":19,"Name":"Lower Kohistan"},{"Id":20,"Name":"Lakki Marwat"},{"Id":21,"Name":"Lower Dir"},{"Id":22,"Name":"Malakand"},{"Id":23,"Name":"Mansehra"},{"Id":24,"Name":"Nowshera"},{"Id":25,"Name":"Shangla"},{"Id":26,"Name":"Swabi"},{"Id":27,"Name":"Tank"},{"Id":28,"Name":"Upper Dir"},{"Id":29,"Name":"Torghar"}],"BUSINESS_TYPE":[{"Id":1,"Name":"Hotels"},{"Id":2,"Name":"Restaurants"},{"Id":3,"Name":"Schools\/Colleges"},{"Id":4,"Name":"Dhaba\/Tea Stall\/Shwarma\/Dahi Bhalay"},{"Id":5,"Name":"Tandoor"},{"Id":6,"Name":"Juice Shop"},{"Id":7,"Name":"Kabab Shop"},{"Id":8,"Name":"Mega Marts\/Super Store"},{"Id":9,"Name":"Stores"},{"Id":10,"Name":"Karyana Store"},{"Id":11,"Name":"Fruits\/Dry Fruits\/Vegetables"},{"Id":12,"Name":"Meat Shop"},{"Id":13,"Name":"Poultry\/Fish Shop"},{"Id":14,"Name":"Whole Sale Dealer"},{"Id":15,"Name":"Distribution Point"},{"Id":16,"Name":"Wharehouse"},{"Id":17,"Name":"Bakers and Confectioners"},{"Id":18,"Name":"Small Industry"},{"Id":19,"Name":"Medium Industry"},{"Id":20,"Name":"Large Industry"},{"Id":21,"Name":"Cottage Industry"},{"Id":22,"Name":"Cart"},{"Id":23,"Name":"Cold Storage"},{"Id":24,"Name":"Slaughter House"},{"Id":25,"Name":"Dairy Shop and Form"},{"Id":26,"Name":"Canteen"},{"Id":27,"Name":"Others"},{"Id":28,"Name":"Oil\/Ghee Industry"},{"Id":29,"Name":"Ice Factory"},{"Id":30,"Name":"Salt and Minerals"},{"Id":31,"Name":"Ice Cream Factory"},{"Id":32,"Name":"Water Purification Plant"},{"Id":33,"Name":"Masala"},{"Id":34,"Name":"Papar Factory"},{"Id":35,"Name":"Papar\/Chips\/Pops Factory"}],"ASSISTANT_DIRECTOR":[{"staff_id":1,"staff_name":"Sajjad Ahmad"},{"staff_id":2,"staff_name":"Murad Ali"}],"FSO":[{"staff_id":35,"staff_name":"Shahab"},{"staff_id":36,"staff_name":"Shakeel Ahmad Khan"},{"staff_id":37,"staff_name":"Nawab Ali"},{"staff_id":38,"staff_name":"Shakeel Ahmed"}],"OFFENCE":[{"Id":1,"Name":"Adultration"},{"Id":2,"Name":"Mislabeling\/Misbranding"},{"Id":4,"Name":"Unhygienic Condition"},{"Id":5,"Name":"Banned Items"},{"Id":6,"Name":"Expired Items"}],"SAMPLE_DISCARDED":[{"Id":1,"Name":"Milk"},{"Id":2,"Name":"Meat"},{"Id":3,"Name":"Water"},{"Id":4,"Name":"Beverages"},{"Id":5,"Name":"Diary Products"},{"Id":6,"Name":"Poultry"},{"Id":7,"Name":"Salt"},{"Id":8,"Name":"Spices\/Masala"},{"Id":9,"Name":"Bakary"},{"Id":11,"Name":"Chips\/Pops"},{"Id":12,"Name":"Oil\/Ghee"},{"Id":13,"Name":"Ice"},{"Id":14,"Name":"Non-Food Colors\/Flavours"},{"Id":15,"Name":"Fruit Pulp\/Squash\/Jams\/Pickles"}]} at user of type java.lang.String cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:100)
I Tried a lot but can not find the solution.
The problem is that the value for the key "user" is not actually a json object, it is a String that looks like a json object. This is what you have, formatted and trimmed a little bit:
"user":"{\"DISTRICT\":[...]}"
If this were a json object, it would look like this instead:
"user":{"DISTRICT":[...]}
The double-quotes surrounding the curly braces, as well as the backslashes escaping the double-quotes inside the curly braces, are clues that you're actually working with a String here.
What you could do is retrieve the value of "user" as a String, but then convert it to a json object:
JSONObject obj = new JSONObject(s);
String userString = obj.getString("user");
JSONObject userObject = new JSONObject(userString);