java - JSONArray getValue -


i have teams.json file following content

{ "league": "champions league", "season": "2015/16", "start": "2015-11-01", "end": "2016-03-31", "teams": [      { "name": "spain" },     { "name": "germany"},     { "name": "italy" },     { "name": "brasil" },     { "name": "argentina" } ] 

}

and have jsonarray works fine

    jsonobject jsonobject = (jsonobject) obj;     jsonarray teamlist = (jsonarray) jsonobject.get("teams");     iterator<jsonarray> iterator = teamlist.iterator();         while (iterator.hasnext()) {             system.out.println(iterator.next());         } 

output:

{"name":"spain"} {"name":"germany"} {"name":"italy"} {"name":"brasil"} {"name":"argentina"} 

but want values in array without {"name": ... stuff,

spain, germany,italy,brasil,argentina

you can :

package foo.bar;  import org.json.jsonarray; import org.json.jsonobject;  public class json {      public static void main(string[] args) {          string str = "{\r\n\"league\": \"champions league\",\r\n\"season\": \"2015/16\",\r\n\"start\": \"2015-11-01\",\r\n\"end\": \"2016-03-31\",\r\n\"teams\": [ \r\n    { \"name\": \"spain\" },\r\n    { \"name\": \"germany\"},\r\n    { \"name\": \"italy\" },\r\n    { \"name\": \"brasil\" },\r\n    { \"name\": \"argentina\" }\r\n]}";         jsonobject jsonobject = new jsonobject(str);         jsonarray teamlist = (jsonarray) jsonobject.get("teams");         (object o : teamlist) {             jsonobject team = (jsonobject) o;             system.out.println(team.getstring("name"));         }     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -