合并两个JsonArray

时间:2024-08-09 23:34:14
//合并两个JSONArray
public static String joinJSONArray(JSONArray mData, JSONArray array) {
StringBuffer buffer = new StringBuffer();
buffer.append("[");
try {
int len = mData.size();
for (int i = 0; i < len; i++) {
JSONObject obj1 = (JSONObject) mData.get(i);
if (i == len - 1){
buffer.append(obj1.toString());
}else{
buffer.append(obj1.toString()).append(",");
}
}
len = array.size();
if (len > 0){
buffer.append(",");
}
for (int i = 0; i < len; i++) {
JSONObject obj1 = (JSONObject) array.get(i);
if (i == len - 1){
buffer.append(obj1.toString());
}else{
buffer.append(obj1.toString()).append(",");
}
} } catch (Exception e) {
e.printStackTrace();
logger.error("合并jsonarray异常",e);
}
buffer.append("]");
return buffer.toString();
}