JSONArray outputArr = new JSONArray;outputArr = joinJSONArrayoutputArr data;JSONObject tempData = new JSONObject;tempDataputdata outputArr;data中有数据经过上面代码tempData中的数据为空代码实现
根据你提供的代码,可以看出joinJSONArray方法应该是用来将一个JSONArray对象合并到另一个JSONArray对象中的。假设joinJSONArray方法的实现如下:
public JSONArray joinJSONArray(JSONArray arr1, JSONArray arr2) {
for (int i = 0; i < arr2.length(); i++) {
arr1.put(arr2.get(i));
}
return arr1;
}
那么,经过上面代码的执行,tempData中的数据应该是包含了data中的数据的JSONArray。请注意,tempData是一个JSONObject对象,不是JSONArray对象。
完整的代码如下:
JSONArray outputArr = new JSONArray();
outputArr = joinJSONArray(outputArr, data);
JSONObject tempData = new JSONObject();
tempData.put("data", outputArr);
// joinJSONArray方法的实现
public JSONArray joinJSONArray(JSONArray arr1, JSONArray arr2) {
for (int i = 0; i < arr2.length(); i++) {
arr1.put(arr2.get(i));
}
return arr1;
}
请确保data是一个JSONArray对象,并且joinJSONArray方法的实现正确,才能正确地将data中的数据合并到tempData中
原文地址: http://www.cveoy.top/t/topic/iVwt 著作权归作者所有。请勿转载和采集!