Convert normal Java Array or ArrayList to Json Array in android

前端 未结 8 1458
栀梦
栀梦 2020-11-29 06:15

Is there any way to convert a normal Java array or ArrayList to a Json Array in Android to pass the JSON object to a webservice?

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 06:53

    you need external library

     json-lib-2.2.2-jdk15.jar
    
    List mybeanList = new ArrayList();
    mybeanList.add("S");
    mybeanList.add("b");
    
    JSONArray jsonA = JSONArray.fromObject(mybeanList);
    System.out.println(jsonA);
    

    Google Gson is the best library http://code.google.com/p/google-gson/

提交回复
热议问题