我有一个非常简单的对象数组
Object[] args = new Object[] {"002"};
我的目标是在 Android 中对这个对象数组进行 JSON 序列化,并将结果作为字节数组获取。 Android 中有两个用于 JSON 序列化的类。 JSONArray
和 JSONObject
。我应该使用哪个类?
特别是我不确定如何使用
JSONObject json = new JSONObject();
json.put("key", "value");
在这种情况下是例行公事。
最佳答案
你应该为此使用 JSONArray
JSONArray jsonArray = new JSONArray();
jsonArray.put("002");
byte[] bytes = jsonArray.toString().getBytes()
关于android - JSON 序列化对象数组 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35917018/