1. Entity class Conversion method
Reference article: http://www.cnblogs.com/dflmg/p/6933811.html
2.k-v method (This method is rather stupid, but there is no way, I now do not know whether there is no relevant simple API, can only manually spell a method.) Import org.apache.commons.lang.StringUtils;)
String s = "{' request ': {' Enterpriseid ': ' Ownercode ': ' SunEee01 ', ' item ': ' {' itemname ': ' 1 bear children Xinjiang Figs finished 268g ', ' ItemType ' : ' ZC ', ' barCode ': ' 6924459400256 ', ' Shelflife ': 0, ' ItemCode ': ' xhzwhggcp_268 '},
{' ItemName ': ' 2 good kids Xinjiang Fig finished 268g ', ' itemType ': ' ZC ', ' barCode ': ' 6924459400256 ', ' shelflife ': 1, ' ItemCode ': ' Xhzwhggcp_ 268 '}]}} "; //String s = "{' request ': {' Enterpriseid ':", ' ownercode ': ' SunEee01 ', ' item ': [{' ItemName ': ' Good kid Xinjiang figs finished 268g ', ' ItemType ': ' ZC ', ' barCode ': ' 6924459400256 ', ' shelflife ': 1, ' ItemCode ': ' xhzwhggcp_268 '}]} ";Jsonobject Jsonobject =Jsonobject.fromobject (s); //System.out.println (jsonobject);String Request= jsonobject.getstring ("Request"); //System.out.println (request);Jsonobject Vendordo=Jsonobject.fromobject (Request); //System.out.println (Vendordo);String ent= Vendordo.getstring ("Item"); //Method of Object entity classSystem.out.println (ENT); /*Jsonarray Ents = Vendordo.getjsonarray ("item"); list<item> ss = (list<item>) jsonarray.tolist (Ents,item.class); for (Item x:ss) {
If the item also has a list object as a property, use the 1 method, see http://www.cnblogs.com/dflmg/p/6933811.html System.out.println (X.getitemname ()) ; }*/string[] Many= Ent.split ("\\},\\{"); if(many.length==1) {String one= Many[0].substring (1,ent.length ()-1); Jsonobject Joss=Jsonobject.fromobject (one); String ItemName= Joss.getstring ("ItemName"); System.out.println (ItemName); }Else{ for(inti=0;i<many.length;i++){ if(i==0) {String frist= many[i].substring (1) + "}"; Jsonobject Joss=Jsonobject.fromobject (frist); String ItemName= Joss.getstring ("ItemName"); System.out.println (ItemName); }Else if(i==many.length-1) {String middle= "{" +stringutils.substringbefore (Many[i], "]"); Jsonobject Joss=jsonobject.fromobject (middle); String ItemName= Joss.getstring ("ItemName"); System.out.println (ItemName); }Else{String last= "{" +many[i]+ "}"; Jsonobject Joss=Jsonobject.fromobject (last); String ItemName= Joss.getstring ("ItemName"); System.out.println (ItemName); } }}
Java extracts JSON values when you encounter an array collection using the K-v transform