json - Android object collection having same value -
this question has answer here:
- how parse json in android 4 answers
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 collect same set of object having same marks in 1 list , other object having different marks in different list.please help..thanks in advance.
thats not valid json data,you can validate here putting json data. https://jsonformatter.curiousconcept.com/.
your json data should 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 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")); } } }
Comments
Post a Comment