json与对象互转-1
json文件请看:json与对象互转-1.json
import java.util.List; /** * 用户打卡信息 */ public class Checkindata { private String userid; private String groupname; private String checkin_type;//外出打卡/上下班打卡 private String exception_type; private long checkin_time;//1531373790 private String location_title; private String location_detail; private String wifiname; private String notes; private String wifimac; private List<String> mediaids; public Checkindata(){} ; public Checkindata(String userid,String groupname,String checkin_type,String exception_type, long checkin_time,String location_title,String location_detail,String wifiname,String notes, String wifimac,List<String> mediaids) { super(); this.userid = userid; this.groupname = groupname; this.checkin_type = checkin_type; this.exception_type = exception_type; this.checkin_time = checkin_time; this.location_title = location_title; this.location_detail = location_detail; this.wifiname = wifiname; this.notes = notes; this.wifimac = wifimac; this.mediaids = mediaids; } //省略N个SET&GET }
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.List; import net.sf.json.JSONObject; import com.google.gson.Gson; public class CheckinList { private int errcode; private String errmsg; private List<Checkindata> checkindata; public CheckinList(List<Checkindata> checkindata,int errcode,String errmsg) { super(); this.checkindata = checkindata; this.errcode = errcode; this.errmsg = errmsg; } public CheckinList() {} //省略N个SET&GET public static void main(String[] args) throws IOException { String file = "json与对象互转-1.json"; File f=new File(file); BufferedReader br=new BufferedReader(new FileReader(f)); String lineinfo=""; StringBuffer sb = new StringBuffer(); while((lineinfo = br.readLine()) != null){ sb.append(lineinfo); } br.close(); System.out.println(sb.toString()); Gson g1 = new Gson(); CheckinList c1 = g1.fromJson(sb.toString(), CheckinList.class); System.out.println(c1.getErrcode()+","+c1.getErrmsg()+":"+c1.getDatas()); for(Checkindata c : c1.getDatas()){ System.out.println(c.getCheckin_time()+","+c.getLocation_title()+","+c.getUserid()+","+c.getLocation_detail()); } System.out.println("1-------------------------------------"); JSONObject jsonObj = JSONObject.fromObject(sb.toString()); String checkindata = jsonObj.getString("checkindata"); System.out.println(checkindata); System.out.println("2-------------------------------------"); String checkin = checkindata.substring(1, checkindata.length() - 1); System.out.println(checkin); System.out.println("3-------------------------------------"); JSONObject jsonDatas = JSONObject.fromObject(checkin); System.out.println(jsonDatas.toString()); System.out.println("4-------------------------------------"); Gson gson = new Gson(); Checkindata c = gson.fromJson(jsonDatas.toString(), Checkindata.class); System.out.println(c.getCheckin_time()+","+c.getLocation_title()); } }
json与对象互转-1.json
{ "errcode":0, "errmsg":"ok", "checkindata":[ { "userid":"MinYongCheng", "groupname":"", "checkin_type":"外出打卡", "exception_type":"", "checkin_time":1531373790, "location_title":"合肥南站", "location_detail":"安徽省合肥市包河区徽州大道与绕城高速交叉口东北", "wifiname":"", "notes":"", "wifimac":"", "mediaids":[ ] }, { "userid":"MinYongCheng", "groupname":"", "checkin_type":"外出打卡", "exception_type":"", "checkin_time":1531382536, "location_title":"金竹坑", "location_detail":"江西省上饶市婺源县秋口镇金竹坑", "wifiname":"", "notes":"", "wifimac":"", "mediaids":[ ] } }
相关推荐
使用json-lib实现json与Java对象的互转
Delphi中JSon SuperObject 使用数据集与JSON对象互转.docx
json与java对象互转
c#与json对象互转 该文件使用原生的类实现 c#对象 与json对象的互相转换
本文实例讲述了Python3实现的字典、列表和json对象互转功能。分享给大家供大家参考,具体如下: python3可以使用json模块操作json json.dumps(): 对json进行编码,对应php的json_encode() json.loads(): 对json进行...
Java中,使用jackson完成json与Java对象互转
string 、对象 、json之间相互互转 ,包含jar包测试类,做了简单的,能使而已!
JSON对象互转的一个小案例,使用的是fastjson,JSON.stringify JSON.parseArray
Gson这个Java类库可以把Java对象转换成JSON,也可以把JSON字符串转换成一个相等的Java对象。Gson支持任意复杂Java对象包括没有源代码的对象。
安卓移动端中实现JSON和对象&数组的相互转换的工具类,代码里有注释
Delphi中JSon_SuperObject_使用数据集与JSON对象互转
* 从一个JSON 对象字符格式中得到一个java对象 * * @param jsonString * @param pojoCalss * @return */ @SuppressWarnings("unchecked") public static <T> T jsonToObject(String jsonString, Class<T> ...
form数据与json对象的互相转换(完整版) * 将web Form 的数据转化成json字符串 * 将json对象的值解析后填入web Form 在AJAX开发中这是关键技术: 1、将form中的数据利用本工具转换成json格式的字符串,再通过ajax传...
Delphi中JSon_SuperObject_使用数据集与JSON对象互转
NULL 博文链接:https://jayung.iteye.com/blog/2225274
json对象转化为字符串,也可以字符串的json转换为对象
高效的JSON与Object互转的工具源代码,如果JSON数据未按该工具规定的数据格式转化成对象,将转化成java.util.Map实例。 (比JSON官方的API更适用。支持对象之间的多级引用,支持Map, List等集合。不需要引用其它中间...
工具类---实现实体类与Json的转换
json-lib-2.4-jdk15 jakarta commons-lang 2.5 jakarta commons-beanutils 1.8.0 jakarta commons-collections 3.2.1 jakarta commons-logging 1.1.1 ezmorph 1.0.6
最近在搞一个json的需求,对端提供的json首字母都是大写的。这样转json起来有点难度,从csdn上贴的大神的解决方式,分值比较高。然后自己修改了下,符合自己的需求,就放在这里了。