How to add a String Array in a JSON object?

后端 未结 5 739
孤城傲影
孤城傲影 2021-01-03 19:49

I am trying to create this JSON object on android. I am stuck on how to add a string array in the object.

A = {
    \"class\" : \"4\" ,
    \"name\" : [\"joh         


        
5条回答
  •  难免孤独
    2021-01-03 20:39

    You are getting error because of this.

    school.put("name", ["john", "mat", "jason", "matthew"] );
                       ^                                 ^   
    

    Do like this.

    school.put("name", new JSONArray("[\"john\", \"mat\", \"jason\", \"matthew\"]"));
    

提交回复
热议问题