It is simply a question tormented the whole day, and good depressed mood finally released, finally retired and sit think it is not what should be recorded.
First of all the json string is returned from the external network interface to data, my friends want to know can be copied to json parser to look over format: 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": "Ningbo electronic port", "Status": "CUSPASS", "EventName": "customs clearance"}, { "ImExIdentifier": "", "TransportStatusCode": ". 27301 loading manifest data transmission is successful", "TransportStatusNameEN ":" "," DateOrTimeOrPeriod ":" 2019-10-31 13:44:41 "," TimeZoneIdentifier ":" PRC "," PlaceLocationQualifier ":" NBEPORT "," PlaceOrLocationIdentification ":" "," PlaceOrLocation ":" "," Remark ":" Ningbo electronic port "," Status ":" MFT "," EventName ":" load manifest "}, {" ImExIdentifier ":" E "," TransportStatusCode ":" heavy boxes on board ", "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 ":" Beilun four dock "," Remark ":" Ningbo E-port "," Status ":" LOAD "," EventName ":" shipped "}]}]}] , "error": ""}
During the fastjson package with the alibab want to peel layer by layer, this json, which wastes a lot of time or no effect, estimated to be using the wrong method, here affixed directly to the success of the method.
First of all I would first build entity classes, here is relatively simple, according to json format is one level down to write, it is directly attached to the code. (Getset and constructors I will not put up a bit too much space)
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;
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 ;
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;
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 ;
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;
Just think of it not to fold it, it will not be too long, but I'm too lazy, I'm sorry I will not go back to operate.
After the completion of the construction entity class I tried it, and no longer use alibab of fastjson, use the following package:
import net.sf.json.JSONObject;
maven dependency follows:
<dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency>
The final code is as follows:
. 1 Import net.sf.json.JSONArray; 2 Import net.sf.json.JSONObject; . 3 . 4 public class Test02 { . 5 . 6 public static void main (String [] args) { . 7 . 8 String JSON = "This is a long giant above of the JSON " ; . 9 10 // get json objects . 11 the jSONObject jsonObject = JSONObject.fromObject (json); 12 is // obtaining therein biz_result array 13 is the JSONArray biz_result = jsonObject.getJSONArray (" biz_result " ); 14 // Get array someone element 15 Biz_result.getString biz_resultString = String (0 ); 16 // in the array to the array again converted json objects . 17 the JSONObject jsonObject1 = JSONObject.fromObject (biz_resultString); 18 is // Get value by the getString . 19 String manifestInfo jsonObject1.getString = ( "ManifestInfo" ); 20 is // removed to give the first bracket json format 21 is String manifestInfo.substring the substring = (. 1 ); 22 is String subString substring.substring = (0, substring.length () -. 1 ); 23 is // obtained json json format after converted to the object 24 the JSONObject JB3 =JSONObject.fromObject (subString); 25 // get the desired value. 26 is String vesselName = jb3.getString ( "VesselName" ); 27 System.out.println (vesselName); 28 29 } 30 }
Still have to develop the habit of writing comments, if you do not write comments Tieshanglai, I have looked uncomfortable, and finally got the required data:
COSCO YINGKOU
If you can help, that's fine.
Any errors or suggestions, please leave a message.