List<String> apFilePaths = Matisse.obtainPathResult(intent); if (apFilePaths != null && apFilePaths.size() > 0) { JSONArray pathMembers = new JSONArray(); JSONArray tempMembers = new JSONArray(); for (int i = 0; i < apFilePaths.size(); i++) { pathMembers.put(apFilePaths.get(i));//没有键值对 File tempFile = new File(apFilePaths.get(i)); if (tempFile.exists()) { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("path", apFilePaths.get(i)); jsonObject.put("size", tempFile.length()); } catch (JSONException e) { e.printStackTrace(); } tempMembers.put(jsonObject);//有键值对 } } JSONObject jsonObject = new JSONObject(); try { jsonObject.put("apFilePaths", pathMembers);//有键值对的列表 JSONArray jsonObject.put("tempFiles", tempMembers);//没有键值对的列表 JSONArray } catch (JSONException e) { e.printStackTrace(); }
jsonObject.toString()