JSONObject,JSONArray(alibaba.fastjson)
String转Object: Object obj = str; //直接转就行
Object转String: String str = obj.toString;
String转JSONObject: JSONObject jsonObject = JSONObject.parseObject(str); 注(String str = "{"abc":"1","hahah":"2"}";//str必须满足以下格式)
获取JSONObject内的值:jsonObject.getString("abc");
JSONObject转String: String str = jsonObject.toString();
String转JSONArray: JSONArray jsonArray = JSONArray.parseArray(str); 注(String str = [{'MSI':'1440466106507','sex':'男','age':'18'},{'MSI':'1440466106507','sex':'女','age':'17'}];//str必须满足以下格式,内部就是多个JSONObject)
获取JSONArray内的第一个JSONObject:JSONObject jsonObject = jsonArray.getJSONObject(0);
JSONArray转String: String str = jsonArray.toString();
实体类转String :String str = JSONObject.toJSONString(user);
JSONObject转实体类: User user = JSONObject.parseObject(jsonObject.toString,User.class);
JSONArray转实体类list<T>: List<User> = JSONArray.parseArray(jsonArray.toString,User.class);
它们之间的相互转换,在一定程度上必须满足一些条件,很容易确定使用哪一个方法