JSONArray
使用jsonArray存储数组数据。
JSONObject jsonObject = new JSONObject();
Log.i(TAG,"JSON:" + jsonObject.toString());
try {
jsonObject.put("classLevelNum",5);
JSONArray jsonArray = new JSONArray();
jsonArray.put("1");
jsonArray.put("2");
jsonArray.put("3");
jsonArray.put("4");
jsonArray.put("5");
jsonObject.put("classLevelValues",jsonArray);
Log.i(TAG,"JSON:" + jsonObject.toString());
}catch (Exception e) {
}
2023-07-04 10:16:50.285 14245-14245/cn.jj.myapplication I/JJWorld.MainActivity: JSON:{}
2023-07-04 10:16:50.286 14245-14245/cn.jj.myapplication I/JJWorld.MainActivity: JSON:{"classLevelNum":5,"classLevelValues":["1","2","3","4","5"]}