直接上代码吧,记得使用完成以后一定要清空你的对象,要不然里面的数据会无线呢叠加:
class JSONObjectDanLI {
private JSONObject jsonObject;
//构造函数私有化
private JSONObjectDanLI(){
jsonObject = new JSONObject();
}
private static JSONObjectDanLI jsonObjectDanLI;
//提供一个公共的、静态的、返回值类型是当前本类的对象
public static JSONObjectDanLI getGsonDanli(){
if(jsonObjectDanLI == null){
synchronized (OkHttpUtils.class){
if(jsonObjectDanLI == null) {
jsonObjectDanLI = new JSONObjectDanLI();
}
}
}
return jsonObjectDanLI;
}
public JSONObject getJSONObject(){
return jsonObject;
}
//清空jsonObject里面数据,干什么用你们都懂
public void remove(){
while(jsonObject.length()>0)
jsonObject.remove(jsonObject.keys().next());
}
}