Convert normal Java Array or ArrayList to Json Array in android

前端 未结 8 1427
栀梦
栀梦 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条回答
  •  执念已碎
    2020-11-29 06:47

    If you want or need to work with a Java array then you can always use the java.util.Arrays utility classes' static asList() method to convert your array to a List.

    Something along those lines should work.

    String mStringArray[] = { "String1", "String2" };
    
    JSONArray mJSONArray = new JSONArray(Arrays.asList(mStringArray));
    

    Beware that code is written offhand so consider it pseudo-code.

提交回复
热议问题