package Data;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Author: wangliu_petter 叉哥
* QQ:1206420658
* Date: 16-3-24
* Time: 下午 18:00
*/
public class BaseData {
public int appId;
public String appName;
public String pkgName;
public String country;
public String language;
public String toJsonString(){
JSONObject jsonObject=new JSONObject();
try {
jsonObject.put("appId",this.appId);
jsonObject.put("appName",this.appName);
jsonObject.put("country",this.country);
jsonObject.put("language",this.language);
return jsonObject.toString();
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
public static BaseData JosonStringtoObject(String jsonString){
BaseData baseData=new BaseData();
try {
JSONObject jsonObject=new JSONObject(jsonString);
baseData.appId=jsonObject.optInt("appId");
baseData.appName=jsonObject.optString("appName");
baseData.pkgName=jsonObject.optString("pkgName");
baseData.country=jsonObject.optString("country");
baseData.language=jsonObject.optString("language");
} catch (Exception e) {
// TODO: handle exception
}
return baseData;
}
}
简单的android数据类和Json转换(Data Json)
最新推荐文章于 2024-08-10 03:40:32 发布