就很简单的一个问题折磨了整整一天,压抑的心情终于释放了,终于闲下来觉得是不是应该记录一下。

首先这个json串是从外网接口返回的数据,想要了解的朋友们可以复制到json解析器中看一下格式:https://www.json.cn/#

{"status":"True","biz_result":[{"PartyFunctionCode":"NBEPORT","PartyIdentifier":"container","PartyName":"宁波电子口岸","ManifestInfo":[{"LadingBillNumber":"COSU6224023460B","ShippingCompanyName":"","VesselNameCode":"COSCO YINGKOU","VesselName":"COSCO YINGKOU","PlaceOfLoading":"","PlaceOfDischarge":"","VoyageNumber":"130W","DirectionCode":"","VesselCallNumber":"","IMONumber":""}],"ContainerInfo":[{"ContainerNumber":"FCIU9840537","ContainerOperator":"COS","SealNumber":"11374417","CodeOfSizeAndType":"","ContainerLoadingStatusCode":"","ContainerTareWeight":"0","TransportMeansType":"","VehicleNumber":"","ContainerStatusInformation":[{"ImExIdentifier":"","TransportStatusCode":"码头已经放行","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-25 17:34:49","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"","PlaceOrLocation":"","Remark":"宁波电子口岸","Status":"DOCKPASS","EventName":""},{"ImExIdentifier":"E","TransportStatusCode":"重箱进港","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-24 13:29:00","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"BLCT3","PlaceOrLocation":"北仑四期码头","Remark":"宁波电子口岸","Status":"INOUT","EventName":"进港"},{"ImExIdentifier":"E","TransportStatusCode":"海关放行","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-25 11:04:37","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"","PlaceOrLocation":"","Remark":"宁波电子口岸","Status":"CUSPASS","EventName":"海关放行"},{"ImExIdentifier":"","TransportStatusCode":"27301 装载舱单数据传输成功。","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-31 13:44:41","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"","PlaceOrLocation":"","Remark":"宁波电子口岸","Status":"MFT","EventName":"装载舱单"},{"ImExIdentifier":"E","TransportStatusCode":"重箱装船","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-11-01 16:13:00","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"BLCT3","PlaceOrLocation":"北仑四期码头","Remark":"宁波电子口岸","Status":"LOAD","EventName":"装船"},{"ImExIdentifier":"","TransportStatusCode":"开船","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-11-01 22:00:00","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"BLCT3","PlaceOrLocation":"北仑四期码头","Remark":"宁波电子口岸","Status":"BERTH","EventName":"离港"}]}]},{"PartyFunctionCode":"NBEPORT","PartyIdentifier":"container","PartyName":"宁波电子口岸","ManifestInfo":[{"LadingBillNumber":"COSU6224023460A","ShippingCompanyName":"","VesselNameCode":"COSCO YINGKOU","VesselName":"COSCO YINGKOU","PlaceOfLoading":"","PlaceOfDischarge":"","VoyageNumber":"130W","DirectionCode":"","VesselCallNumber":"","IMONumber":""}],"ContainerInfo":[{"ContainerNumber":"FCIU9840537","ContainerOperator":"COS","SealNumber":"11374417","CodeOfSizeAndType":"","ContainerLoadingStatusCode":"","ContainerTareWeight":"0","TransportMeansType":"","VehicleNumber":"","ContainerStatusInformation":[{"ImExIdentifier":"","TransportStatusCode":"码头已经放行","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-25 17:34:49","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"","PlaceOrLocation":"","Remark":"宁波电子口岸","Status":"DOCKPASS","EventName":""},{"ImExIdentifier":"E","TransportStatusCode":"重箱进港","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-24 13:29:00","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"BLCT3","PlaceOrLocation":"北仑四期码头","Remark":"宁波电子口岸","Status":"INOUT","EventName":"进港"},{"ImExIdentifier":"E","TransportStatusCode":"海关放行","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-25 11:04:27","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"","PlaceOrLocation":"","Remark":"宁波电子口岸","Status":"CUSPASS","EventName":"海关放行"},{"ImExIdentifier":"","TransportStatusCode":"27301 装载舱单数据传输成功。","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-10-31 13:44:41","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"","PlaceOrLocation":"","Remark":"宁波电子口岸","Status":"MFT","EventName":"装载舱单"},{"ImExIdentifier":"E","TransportStatusCode":"重箱装船","TransportStatusNameEN":"","DateOrTimeOrPeriod":"2019-11-01 16:13:00","TimeZoneIdentifier":"PRC","PlaceLocationQualifier":"NBEPORT","PlaceOrLocationIdentification":"BLCT3","PlaceOrLocation":"北仑四期码头","Remark":"宁波电子口岸","Status":"LOAD","EventName":"装船"}]}]}],"error":""}

期间用了alibab的fastjson包想要一层一层剥开这个json,结果浪费了许多时间还是没有效果,估计是方法使用错了,这里就直接贴上成功的方法。

首先还是先建了实体类,这里比较简单,就是按照json的格式一层一层往下写,就直接贴代码了。

 1 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 2 import java.io.Serializable;
 3 import java.util.List;
 4
 5 @JsonIgnoreProperties(ignoreUnknown = true)
 6 @SuppressWarnings("serial")
 7 public class Result implements Serializable {
 8
 9     private String status;
10     private List<biz_result> biz_result;
11     private String error;
12
13     public Result() {
14         super();
15     }
16
17     public Result(String status, List<biz_result> biz_result, String error) {
18         this.status = status;
19         this.biz_result = biz_result;
20         this.error = error;
21     }
22
23     public String getStatus() {
24         return status;
25     }
26
27     public void setStatus(String status) {
28         this.status = status;
29     }
30
31     public List<biz_result> getbiz_result() {
32         return biz_result;
33     }
34
35     public void setbiz_result(List<biz_result> biz_result) {
36         this.biz_result = biz_result;
37     }
38
39     public String getError() {
40         return error;
41     }
42
43     public void setError(String error) {
44         this.error = error;
45     }
46 }
 1 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 2 import java.io.Serializable;
 3 import java.util.List;
 4
 5 @JsonIgnoreProperties(ignoreUnknown = true)
 6 @SuppressWarnings("serial")
 7 public class biz_result implements Serializable {
 8     private String PartyFunctionCode;
 9     private String PartyIdentifier;
10     private String PartyName;
11     private List<ManifestInfo> ManifestInfo ;
12     private List<ContainerInfo> ContainerInfo ;
13
14     public biz_result() {
15         super();
16     }
17
18     public biz_result(String partyFunctionCode, String partyIdentifier, String partyName, List<ManifestInfo> ManifestInfo, List<ContainerInfo> ContainerInfo) {
19         PartyFunctionCode = partyFunctionCode;
20         PartyIdentifier = partyIdentifier;
21         PartyName = partyName;
22         this.ManifestInfo = ManifestInfo;
23         ContainerInfo = ContainerInfo;
24     }
25
26     public String getPartyFunctionCode() {
27         return PartyFunctionCode;
28     }
29
30     public void setPartyFunctionCode(String partyFunctionCode) {
31         PartyFunctionCode = partyFunctionCode;
32     }
33
34     public String getPartyIdentifier() {
35         return PartyIdentifier;
36     }
37
38     public void setPartyIdentifier(String partyIdentifier) {
39         PartyIdentifier = partyIdentifier;
40     }
41
42     public String getPartyName() {
43         return PartyName;
44     }
45
46     public void setPartyName(String partyName) {
47         PartyName = partyName;
48     }
49
50     public List<ManifestInfo> getManifestInfo() {
51         return ManifestInfo;
52     }
53
54     public void setManifestInfo(List<ManifestInfo> ManifestInfo) {
55         this.ManifestInfo = ManifestInfo;
56     }
57
58     public List<ContainerInfo> getContainerInfo() {
59         return ContainerInfo;
60     }
61
62     public void setContainerInfo(List<ContainerInfo> ContainerInfo) {
63         ContainerInfo = ContainerInfo;
64     }
65 }
  1 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  2 import java.io.Serializable;
  3
  4 @JsonIgnoreProperties(ignoreUnknown = true)
  5 @SuppressWarnings("serial")
  6 public class ManifestInfo implements Serializable {
  7     private String LadingBillNumber;
  8     private String ShippingCompanyName;
  9     private String VesselNameCode;
 10     private String VesselName;
 11     private String PlaceOfLoading;
 12     private String PlaceOfDischarge;
 13     private String VoyageNumber;
 14     private String DirectionCode;
 15     private String VesselCallNumber;
 16     private String IMONumber;
 17
 18     public ManifestInfo() {
 19         super();
 20     }
 21
 22     public ManifestInfo(String ladingBillNumber, String shippingCompanyName, String vesselNameCode, String vesselName, String placeOfLoading, String placeOfDischarge, String voyageNumber, String directionCode, String vesselCallNumber, String IMONumber) {
 23         LadingBillNumber = ladingBillNumber;
 24         ShippingCompanyName = shippingCompanyName;
 25         VesselNameCode = vesselNameCode;
 26         VesselName = vesselName;
 27         PlaceOfLoading = placeOfLoading;
 28         PlaceOfDischarge = placeOfDischarge;
 29         VoyageNumber = voyageNumber;
 30         DirectionCode = directionCode;
 31         VesselCallNumber = vesselCallNumber;
 32         this.IMONumber = IMONumber;
 33     }
 34
 35     public String getLadingBillNumber() {
 36         return LadingBillNumber;
 37     }
 38
 39     public void setLadingBillNumber(String ladingBillNumber) {
 40         LadingBillNumber = ladingBillNumber;
 41     }
 42
 43     public String getShippingCompanyName() {
 44         return ShippingCompanyName;
 45     }
 46
 47     public void setShippingCompanyName(String shippingCompanyName) {
 48         ShippingCompanyName = shippingCompanyName;
 49     }
 50
 51     public String getVesselNameCode() {
 52         return VesselNameCode;
 53     }
 54
 55     public void setVesselNameCode(String vesselNameCode) {
 56         VesselNameCode = vesselNameCode;
 57     }
 58
 59     public String getVesselName() {
 60         return VesselName;
 61     }
 62
 63     public void setVesselName(String vesselName) {
 64         VesselName = vesselName;
 65     }
 66
 67     public String getPlaceOfLoading() {
 68         return PlaceOfLoading;
 69     }
 70
 71     public void setPlaceOfLoading(String placeOfLoading) {
 72         PlaceOfLoading = placeOfLoading;
 73     }
 74
 75     public String getPlaceOfDischarge() {
 76         return PlaceOfDischarge;
 77     }
 78
 79     public void setPlaceOfDischarge(String placeOfDischarge) {
 80         PlaceOfDischarge = placeOfDischarge;
 81     }
 82
 83     public String getVoyageNumber() {
 84         return VoyageNumber;
 85     }
 86
 87     public void setVoyageNumber(String voyageNumber) {
 88         VoyageNumber = voyageNumber;
 89     }
 90
 91     public String getDirectionCode() {
 92         return DirectionCode;
 93     }
 94
 95     public void setDirectionCode(String directionCode) {
 96         DirectionCode = directionCode;
 97     }
 98
 99     public String getVesselCallNumber() {
100         return VesselCallNumber;
101     }
102
103     public void setVesselCallNumber(String vesselCallNumber) {
104         VesselCallNumber = vesselCallNumber;
105     }
106
107     public String getIMONumber() {
108         return IMONumber;
109     }
110
111     public void setIMONumber(String IMONumber) {
112         this.IMONumber = IMONumber;
113     }
114 }
  1 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  2 import java.io.Serializable;
  3 import java.util.List;
  4
  5 @JsonIgnoreProperties(ignoreUnknown = true)
  6 @SuppressWarnings("serial")
  7 public class ContainerInfo  implements Serializable {
  8
  9     private String ContainerNumber;
 10     private String ContainerOperator;
 11     private String SealNumber;
 12     private String CodeOfSizeAndType;
 13     private String ContainerLoadingStatusCode;
 14     private String ContainerTareWeight;
 15     private String TransportMeansType;
 16     private String VehicleNumber;
 17     private List<ContainerStatusInformation> ContainerStatusInformation ;
 18
 19     public ContainerInfo() {
 20         super();
 21     }
 22
 23     public ContainerInfo(String containerNumber, String containerOperator, String sealNumber, String codeOfSizeAndType, String containerLoadingStatusCode, String containerTareWeight, String transportMeansType, String vehicleNumber, List<ContainerStatusInformation> ContainerStatusInformation) {
 24         ContainerNumber = containerNumber;
 25         ContainerOperator = containerOperator;
 26         SealNumber = sealNumber;
 27         CodeOfSizeAndType = codeOfSizeAndType;
 28         ContainerLoadingStatusCode = containerLoadingStatusCode;
 29         ContainerTareWeight = containerTareWeight;
 30         TransportMeansType = transportMeansType;
 31         VehicleNumber = vehicleNumber;
 32         ContainerStatusInformation = ContainerStatusInformation;
 33     }
 34
 35     public String getContainerNumber() {
 36         return ContainerNumber;
 37     }
 38
 39     public void setContainerNumber(String containerNumber) {
 40         ContainerNumber = containerNumber;
 41     }
 42
 43     public String getContainerOperator() {
 44         return ContainerOperator;
 45     }
 46
 47     public void setContainerOperator(String containerOperator) {
 48         ContainerOperator = containerOperator;
 49     }
 50
 51     public String getSealNumber() {
 52         return SealNumber;
 53     }
 54
 55     public void setSealNumber(String sealNumber) {
 56         SealNumber = sealNumber;
 57     }
 58
 59     public String getCodeOfSizeAndType() {
 60         return CodeOfSizeAndType;
 61     }
 62
 63     public void setCodeOfSizeAndType(String codeOfSizeAndType) {
 64         CodeOfSizeAndType = codeOfSizeAndType;
 65     }
 66
 67     public String getContainerLoadingStatusCode() {
 68         return ContainerLoadingStatusCode;
 69     }
 70
 71     public void setContainerLoadingStatusCode(String containerLoadingStatusCode) {
 72         ContainerLoadingStatusCode = containerLoadingStatusCode;
 73     }
 74
 75     public String getContainerTareWeight() {
 76         return ContainerTareWeight;
 77     }
 78
 79     public void setContainerTareWeight(String containerTareWeight) {
 80         ContainerTareWeight = containerTareWeight;
 81     }
 82
 83     public String getTransportMeansType() {
 84         return TransportMeansType;
 85     }
 86
 87     public void setTransportMeansType(String transportMeansType) {
 88         TransportMeansType = transportMeansType;
 89     }
 90
 91     public String getVehicleNumber() {
 92         return VehicleNumber;
 93     }
 94
 95     public void setVehicleNumber(String vehicleNumber) {
 96         VehicleNumber = vehicleNumber;
 97     }
 98
 99     public List<ContainerStatusInformation> getContainerStatusInformation() {
100         return ContainerStatusInformation;
101     }
102
103     public void setContainerStatusInformation(List<ContainerStatusInformation> ContainerStatusInformation) {
104         ContainerStatusInformation = ContainerStatusInformation;
105     }
106 }
  1 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  2 import java.io.Serializable;
  3
  4 @JsonIgnoreProperties(ignoreUnknown = true)
  5 @SuppressWarnings("serial")
  6 public class ContainerStatusInformation implements Serializable {
  7
  8     private String ImExIdentifier;
  9     private String TransportStatusCode;
 10     private String TransportStatusNameEN;
 11     private String DateOrTimeOrPeriod;
 12     private String TimeZoneIdentifier;
 13     private String PlaceLocationQualifier;
 14     private String PlaceOrLocationIdentification;
 15     private String PlaceOrLocation;
 16     private String Remark;
 17     private String Status;
 18     private String EventName;
 19
 20     public ContainerStatusInformation() {
 21         super();
 22     }
 23
 24     public ContainerStatusInformation(String imExIdentifier, String transportStatusCode, String transportStatusNameEN, String dateOrTimeOrPeriod, String timeZoneIdentifier, String placeLocationQualifier, String placeOrLocationIdentification, String placeOrLocation, String remark, String status, String eventName) {
 25         ImExIdentifier = imExIdentifier;
 26         TransportStatusCode = transportStatusCode;
 27         TransportStatusNameEN = transportStatusNameEN;
 28         DateOrTimeOrPeriod = dateOrTimeOrPeriod;
 29         TimeZoneIdentifier = timeZoneIdentifier;
 30         PlaceLocationQualifier = placeLocationQualifier;
 31         PlaceOrLocationIdentification = placeOrLocationIdentification;
 32         PlaceOrLocation = placeOrLocation;
 33         Remark = remark;
 34         Status = status;
 35         EventName = eventName;
 36     }
 37
 38     public String getImExIdentifier() {
 39         return ImExIdentifier;
 40     }
 41
 42     public void setImExIdentifier(String imExIdentifier) {
 43         ImExIdentifier = imExIdentifier;
 44     }
 45
 46     public String getTransportStatusCode() {
 47         return TransportStatusCode;
 48     }
 49
 50     public void setTransportStatusCode(String transportStatusCode) {
 51         TransportStatusCode = transportStatusCode;
 52     }
 53
 54     public String getTransportStatusNameEN() {
 55         return TransportStatusNameEN;
 56     }
 57
 58     public void setTransportStatusNameEN(String transportStatusNameEN) {
 59         TransportStatusNameEN = transportStatusNameEN;
 60     }
 61
 62     public String getDateOrTimeOrPeriod() {
 63         return DateOrTimeOrPeriod;
 64     }
 65
 66     public void setDateOrTimeOrPeriod(String dateOrTimeOrPeriod) {
 67         DateOrTimeOrPeriod = dateOrTimeOrPeriod;
 68     }
 69
 70     public String getTimeZoneIdentifier() {
 71         return TimeZoneIdentifier;
 72     }
 73
 74     public void setTimeZoneIdentifier(String timeZoneIdentifier) {
 75         TimeZoneIdentifier = timeZoneIdentifier;
 76     }
 77
 78     public String getPlaceLocationQualifier() {
 79         return PlaceLocationQualifier;
 80     }
 81
 82     public void setPlaceLocationQualifier(String placeLocationQualifier) {
 83         PlaceLocationQualifier = placeLocationQualifier;
 84     }
 85
 86     public String getPlaceOrLocationIdentification() {
 87         return PlaceOrLocationIdentification;
 88     }
 89
 90     public void setPlaceOrLocationIdentification(String placeOrLocationIdentification) {
 91         PlaceOrLocationIdentification = placeOrLocationIdentification;
 92     }
 93
 94     public String getPlaceOrLocation() {
 95         return PlaceOrLocation;
 96     }
 97
 98     public void setPlaceOrLocation(String placeOrLocation) {
 99         PlaceOrLocation = placeOrLocation;
100     }
101
102     public String getRemark() {
103         return Remark;
104     }
105
106     public void setRemark(String remark) {
107         Remark = remark;
108     }
109
110     public String getStatus() {
111         return Status;
112     }
113
114     public void setStatus(String status) {
115         Status = status;
116     }
117
118     public String getEventName() {
119         return EventName;
120     }
121
122     public void setEventName(String eventName) {
123         EventName = eventName;
124     }
125 }

才想起来要不要折叠一下,这会不会太长了,但是我实在太懒了,对不起我就不去重新操作了。

实体类建完以后我就尝试了一下,也不再使用alibab的fastjson,使用如下这个包:

import net.sf.json.JSONObject;

maven依赖如下:

<dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
</dependency>

最终代码如下:

 1 public static void main(String[]args){
 2
 3         String json = "{\"status\":\"True\",\"biz_result\":[{\"PartyFunctionCode\":\"NBEPORT\",\"PartyIdentifier\":\"container\",\"PartyName\":\"宁波电子口岸\",\"ManifestInfo\":[{\"LadingBillNumber\":\"COSU6224023460B\",\"ShippingCompanyName\":\"\",\"VesselNameCode\":\"COSCO YINGKOU\",\"VesselName\":\"COSCO YINGKOU\",\"PlaceOfLoading\":\"\",\"PlaceOfDischarge\":\"\",\"VoyageNumber\":\"130W\",\"DirectionCode\":\"\",\"VesselCallNumber\":\"\",\"IMONumber\":\"\"}],\"ContainerInfo\":[{\"ContainerNumber\":\"FCIU9840537\",\"ContainerOperator\":\"COS\",\"SealNumber\":\"11374417\",\"CodeOfSizeAndType\":\"\",\"ContainerLoadingStatusCode\":\"\",\"ContainerTareWeight\":\"0\",\"TransportMeansType\":\"\",\"VehicleNumber\":\"\",\"ContainerStatusInformation\":[{\"ImExIdentifier\":\"\",\"TransportStatusCode\":\"码头已经放行\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-25 17:34:49\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"\",\"PlaceOrLocation\":\"\",\"Remark\":\"宁波电子口岸\",\"Status\":\"DOCKPASS\",\"EventName\":\"\"},{\"ImExIdentifier\":\"E\",\"TransportStatusCode\":\"重箱进港\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-24 13:29:00\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"BLCT3\",\"PlaceOrLocation\":\"北仑四期码头\",\"Remark\":\"宁波电子口岸\",\"Status\":\"INOUT\",\"EventName\":\"进港\"},{\"ImExIdentifier\":\"E\",\"TransportStatusCode\":\"海关放行\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-25 11:04:37\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"\",\"PlaceOrLocation\":\"\",\"Remark\":\"宁波电子口岸\",\"Status\":\"CUSPASS\",\"EventName\":\"海关放行\"},{\"ImExIdentifier\":\"\",\"TransportStatusCode\":\"27301 装载舱单数据传输成功。\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-31 13:44:41\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"\",\"PlaceOrLocation\":\"\",\"Remark\":\"宁波电子口岸\",\"Status\":\"MFT\",\"EventName\":\"装载舱单\"},{\"ImExIdentifier\":\"E\",\"TransportStatusCode\":\"重箱装船\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-11-01 16:13:00\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"BLCT3\",\"PlaceOrLocation\":\"北仑四期码头\",\"Remark\":\"宁波电子口岸\",\"Status\":\"LOAD\",\"EventName\":\"装船\"},{\"ImExIdentifier\":\"\",\"TransportStatusCode\":\"开船\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-11-01 22:00:00\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"BLCT3\",\"PlaceOrLocation\":\"北仑四期码头\",\"Remark\":\"宁波电子口岸\",\"Status\":\"BERTH\",\"EventName\":\"离港\"}]}]},{\"PartyFunctionCode\":\"NBEPORT\",\"PartyIdentifier\":\"container\",\"PartyName\":\"宁波电子口岸\",\"ManifestInfo\":[{\"LadingBillNumber\":\"COSU6224023460A\",\"ShippingCompanyName\":\"\",\"VesselNameCode\":\"COSCO YINGKOU\",\"VesselName\":\"COSCO YINGKOU\",\"PlaceOfLoading\":\"\",\"PlaceOfDischarge\":\"\",\"VoyageNumber\":\"130W\",\"DirectionCode\":\"\",\"VesselCallNumber\":\"\",\"IMONumber\":\"\"}],\"ContainerInfo\":[{\"ContainerNumber\":\"FCIU9840537\",\"ContainerOperator\":\"COS\",\"SealNumber\":\"11374417\",\"CodeOfSizeAndType\":\"\",\"ContainerLoadingStatusCode\":\"\",\"ContainerTareWeight\":\"0\",\"TransportMeansType\":\"\",\"VehicleNumber\":\"\",\"ContainerStatusInformation\":[{\"ImExIdentifier\":\"\",\"TransportStatusCode\":\"码头已经放行\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-25 17:34:49\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"\",\"PlaceOrLocation\":\"\",\"Remark\":\"宁波电子口岸\",\"Status\":\"DOCKPASS\",\"EventName\":\"\"},{\"ImExIdentifier\":\"E\",\"TransportStatusCode\":\"重箱进港\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-24 13:29:00\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"BLCT3\",\"PlaceOrLocation\":\"北仑四期码头\",\"Remark\":\"宁波电子口岸\",\"Status\":\"INOUT\",\"EventName\":\"进港\"},{\"ImExIdentifier\":\"E\",\"TransportStatusCode\":\"海关放行\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-25 11:04:27\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"\",\"PlaceOrLocation\":\"\",\"Remark\":\"宁波电子口岸\",\"Status\":\"CUSPASS\",\"EventName\":\"海关放行\"},{\"ImExIdentifier\":\"\",\"TransportStatusCode\":\"27301 装载舱单数据传输成功。\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-10-31 13:44:41\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"\",\"PlaceOrLocation\":\"\",\"Remark\":\"宁波电子口岸\",\"Status\":\"MFT\",\"EventName\":\"装载舱单\"},{\"ImExIdentifier\":\"E\",\"TransportStatusCode\":\"重箱装船\",\"TransportStatusNameEN\":\"\",\"DateOrTimeOrPeriod\":\"2019-11-01 16:13:00\",\"TimeZoneIdentifier\":\"PRC\",\"PlaceLocationQualifier\":\"NBEPORT\",\"PlaceOrLocationIdentification\":\"BLCT3\",\"PlaceOrLocation\":\"北仑四期码头\",\"Remark\":\"宁波电子口岸\",\"Status\":\"LOAD\",\"EventName\":\"装船\"}]}]}],\"error\":\"\"}";
 4
 5         //得到json对象
 6         JSONObject jsonObject = JSONObject.fromObject(json);
 7         //获取其中的biz_result数组
 8         JSONArray biz_result = jsonObject.getJSONArray("biz_result");
 9         //获取数组中的某位元素
10         String biz_resultString = biz_result.getString(0);
11         //将数组中的这个数组再次转换成json对象
12         JSONObject jsonObject1 = JSONObject.fromObject(biz_resultString);
13         //通过getString获取value
14         String manifestInfo = jsonObject1.getString("ManifestInfo");
15         //去除首位中括号得到json格式
16         String substring = manifestInfo.substring(1);
17         String subString = substring.substring(0,substring.length()-1);
18         //得到json格式以后再转换成json对象
19         JSONObject jb3 = JSONObject.fromObject(subString);
20         //得到需要的值。
21         String vesselName = jb3.getString("VesselName");
22         System.out.println(vesselName);
23
24     }

还是得养成写注释的习惯,要是不写注释贴上来,我自己都看着不舒服,最终得到了需要的数据

COSCO YINGKOU

如果能帮上忙,那就再好不过了。

如有错误或建议,欢迎留言。

12-22 14:56