//合并两个JSONArray
public static JSONArray joinJSONArray(JSONArray mData, JSONArray array) {
StringBuffer buffer = new StringBuffer();
try {
int len = mData.length();
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.length();
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(",");
}
buffer.insert(0, "[").append("]");
return new JSONArray(buffer.toString());
} catch (Exception e) {
}
return null;
}
Java:合并两个JSONArray
最新推荐文章于 2024-09-20 10:00:57 发布