小弟新人,不知道怎么解析dhl网站传回来的json文件,有代码最好,谢谢啦
{
"results" : [ {
"id" : "6582515623",
"label" : "运单",
"type" : "airwaybill",
"duplicate" : false,
"delivery" : {
"code" : "101",
"status" : "delivered"
},
"origin" : {
"value" : "SHANGHAI - SHANGHAI - CHINA, PEOPLES REPUBLIC",
"label" : "发件地服务区域",
"url" : "http://www.cn.dhl.com/en/country_profile.html"
},
"destination" : {
"value" : "KUALA LUMPUR - 40470 SHAH ALAM SELANGOR DARUL EHSA - MALAYSIA",
"label" : "目的地服务区域",
"url" : "http://www.dhl.com.my/en/country_profile.html"
},
"description" : "已签收: MS SANDRA 星期三, 一月 06, 2016 于 13:54",
"hasDuplicateShipment" : false,
"signature" : {
"link" : {
"url" : "https://webpod.dhl.com/webPOD/DHLePODRequest?hwb=H%2B8q%2Bsy%2BDgBfBxY4TPyQHQ%3D%3D&pudate=yHkb%2Fogas7GpGJE7%2ByaM0A%3D%3D&appuid=9u1%2BsSO1fsdK7F6MTNnRjg%3D%3D&language=zh&country=CN",
"label" : "获取电子签收凭证"
},
"type" : "epod",
"description" : "星期三, 一月 06, 2016 于 13:54",
"signatory" : "MS SANDRA",
"label" : "已签收",
"help" : "help"
},
"pieces" : {
"value" : 1,
"label" : "件",
"showSummary" : true,
"pIds" : [ "JD014600001868677611" ]
},
"checkpoints" : [ {
"counter" : 4,
"description" : "快件已完成清关手续并从海关放行 EAST CHINA AREA - CHINA, PEOPLES REPUBLIC",
"time" : "21:55",
"date" : "星期一, 一月 04, 2016 ",
"location" : "EAST CHINA AREA - CHINA, PEOPLES REPUBLIC"
}, {
"counter" : 3,
"description" : "离开转运地 SHANGHAI - CHINA, PEOPLES REPUBLIC",
"time" : "21:47",
"date" : "星期一, 一月 04, 2016 ",
"location" : "SHANGHAI - CHINA, PEOPLES REPUBLIC",
"totalPieces" : 1,
"pIds" : [ "JD014600001868677611" ]
}, {
"counter" : 2,
"description" : "正在(已经)安排下一站的转运 SHANGHAI - CHINA, PEOPLES REPUBLIC",
"time" : "21:42",
"date" : "星期一, 一月 04, 2016 ",
"location" : "SHANGHAI - CHINA, PEOPLES REPUBLIC",
"totalPieces" : 1,
"pIds" : [ "JD014600001868677611" ]
}, {
"counter" : 1,
"description" : "快件已从发件人处提取",
"time" : "20:20",
"date" : "星期一, 一月 04, 2016 ",
"location" : "SHANGHAI - CHINA, PEOPLES REPUBLIC"
} ],
"checkpointLocationLabel" : "位置",
"checkpointTimeLabel" : "时间"
} ]
}
如何最简单的用java解析这个json文件
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答
- 林深 2016-01-27 04:20关注
可以拆分成下面这几个model
================================= package ; public class Delivery { private String code; private String status; public void setCode(String code){ this.code = code; } public String getCode(){ return this.code; } public void setStatus(String status){ this.status = status; } public String getStatus(){ return this.status; } } ================================= package ; public class Origin { private String value; private String label; private String url; public void setValue(String value){ this.value = value; } public String getValue(){ return this.value; } public void setLabel(String label){ this.label = label; } public String getLabel(){ return this.label; } public void setUrl(String url){ this.url = url; } public String getUrl(){ return this.url; } } ================================= package ; public class Destination { private String value; private String label; private String url; public void setValue(String value){ this.value = value; } public String getValue(){ return this.value; } public void setLabel(String label){ this.label = label; } public String getLabel(){ return this.label; } public void setUrl(String url){ this.url = url; } public String getUrl(){ return this.url; } } ================================= package ; public class Link { private String url; private String label; public void setUrl(String url){ this.url = url; } public String getUrl(){ return this.url; } public void setLabel(String label){ this.label = label; } public String getLabel(){ return this.label; } } ================================= package ; public class Signature { private Link link; private String type; private String description; private String signatory; private String label; private String help; public void setLink(Link link){ this.link = link; } public Link getLink(){ return this.link; } public void setType(String type){ this.type = type; } public String getType(){ return this.type; } public void setDescription(String description){ this.description = description; } public String getDescription(){ return this.description; } public void setSignatory(String signatory){ this.signatory = signatory; } public String getSignatory(){ return this.signatory; } public void setLabel(String label){ this.label = label; } public String getLabel(){ return this.label; } public void setHelp(String help){ this.help = help; } public String getHelp(){ return this.help; } } ================================= package ; public class PIds { } ================================= package ; import java.util.List; public class Pieces { private int value; private String label; private boolean showSummary; private List<pIds> pIds ; public void setValue(int value){ this.value = value; } public int getValue(){ return this.value; } public void setLabel(String label){ this.label = label; } public String getLabel(){ return this.label; } public void setShowSummary(boolean showSummary){ this.showSummary = showSummary; } public boolean getShowSummary(){ return this.showSummary; } public void setPIds(List<pIds> pIds){ this.pIds = pIds; } public List<pIds> getPIds(){ return this.pIds; } } ================================= package ; public class Checkpoints { private int counter; private String description; private String time; private String date; private String location; public void setCounter(int counter){ this.counter = counter; } public int getCounter(){ return this.counter; } public void setDescription(String description){ this.description = description; } public String getDescription(){ return this.description; } public void setTime(String time){ this.time = time; } public String getTime(){ return this.time; } public void setDate(String date){ this.date = date; } public String getDate(){ return this.date; } public void setLocation(String location){ this.location = location; } public String getLocation(){ return this.location; } } ================================= package ; import java.util.List; public class Results { private String id; private String label; private String type; private boolean duplicate; private Delivery delivery; private Origin origin; private Destination destination; private String description; private boolean hasDuplicateShipment; private Signature signature; private Pieces pieces; private List<checkpoints> checkpoints ; private String checkpointLocationLabel; private String checkpointTimeLabel; public void setId(String id){ this.id = id; } public String getId(){ return this.id; } public void setLabel(String label){ this.label = label; } public String getLabel(){ return this.label; } public void setType(String type){ this.type = type; } public String getType(){ return this.type; } public void setDuplicate(boolean duplicate){ this.duplicate = duplicate; } public boolean getDuplicate(){ return this.duplicate; } public void setDelivery(Delivery delivery){ this.delivery = delivery; } public Delivery getDelivery(){ return this.delivery; } public void setOrigin(Origin origin){ this.origin = origin; } public Origin getOrigin(){ return this.origin; } public void setDestination(Destination destination){ this.destination = destination; } public Destination getDestination(){ return this.destination; } public void setDescription(String description){ this.description = description; } public String getDescription(){ return this.description; } public void setHasDuplicateShipment(boolean hasDuplicateShipment){ this.hasDuplicateShipment = hasDuplicateShipment; } public boolean getHasDuplicateShipment(){ return this.hasDuplicateShipment; } public void setSignature(Signature signature){ this.signature = signature; } public Signature getSignature(){ return this.signature; } public void setPieces(Pieces pieces){ this.pieces = pieces; } public Pieces getPieces(){ return this.pieces; } public void setCheckpoints(List<checkpoints> checkpoints){ this.checkpoints = checkpoints; } public List<checkpoints> getCheckpoints(){ return this.checkpoints; } public void setCheckpointLocationLabel(String checkpointLocationLabel){ this.checkpointLocationLabel = checkpointLocationLabel; } public String getCheckpointLocationLabel(){ return this.checkpointLocationLabel; } public void setCheckpointTimeLabel(String checkpointTimeLabel){ this.checkpointTimeLabel = checkpointTimeLabel; } public String getCheckpointTimeLabel(){ return this.checkpointTimeLabel; } } ================================= package ; import java.util.List; public class Root { private List<results> results ; public void setResults(List<results> results){ this.results = results; } public List<results> getResults(){ return this.results; } }
解析的时候使用Gson的jar包
Gson gson = new Gson(); Result result = gson.fromJson(result,Result.class);
最后给你几个json转java文件的链接:
http://www.bejson.com/json2javapojo/
http://www.jsonschema2pojo.org/本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 删除和修改功能无法调用
- ¥15 kafka topic 所有分副本数修改
- ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
- ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
- ¥40 串口调试助手打开串口后,keil5的代码就停止了
- ¥15 电脑最近经常蓝屏,求大家看看哪的问题
- ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
- ¥50 C++五子棋AI程序编写
- ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
- ¥15 SQL Server analysis services 服务安装失败