I have Json object in format { "result": { "name": "ram", "mark": "50" }, { "name": "ram", "mark": "60" }, { "name": "ram", "mark": "50" }, { "name": "ram", mark: "50" }, { "name": "ram", "mark": "50" }, { "name": "ram", "mark": "80" }, { "name": "ram", "mark": "50" } } . How to collect same set of object having same marks in one list and other object having different marks in different list.please help..thanks in advance.
Asked
Active
Viewed 86 times
-1
-
1First, what have you tried? Post the relevant code along with any errors you are facing. Second, is this a valid JSON at all? The _mark_ tags are not enclosed in double quotes (should be `"mark"`). – Siddharth Lele Feb 06 '16 at 05:13
1 Answers
1
Thats not the valid json data,you can validate it here by putting your json data. https://jsonformatter.curiousconcept.com/.
Your json data should be like:
{
"result": [{
"name": "ram",
"mark": "50"
},
{
"name": "raj",
"mark": "60"
},
{
"name": "ramesh",
"mark": "70"
},
{
"name": "manish",
"mark": "50"
},
{
"name": "priya",
"mark": "50"
},
{
"name": "shiv",
"mark": "80"
},
{
"name": "pankaj",
"mark": "50"
}]
}
And code for this is:
List list = new ArrayList<String>();
JSON Object json = new JSONObject();
if(json.has("result")){
JSONArray array = json.getJSONArray("result");
if(array.length() > 0){
for(int i=0;i<array.length();i++){
JSONObject result = array.getJSONObject(i);
list.add(result.getString("mark"));
}
}
}

Balraj Allam
- 611
- 6
- 24