A personal collection for the next use.
The JSON format for front-end transmission is:
[{"Suppliercode": "Gylhld_gycqlt3_gycqlt1", "ProductName": "Le and Ledou package (adult)", "Datahandelmethod": "1", "ProductType": "1", "YSCPCBJ": "Effectivetime": "2016-01-27 00:00:00", "Invalidtime": "2016-02-29 00:00:00", "Status": "1", "id": " 7066cb7c-fd52-4949-b7a1-776812995023 "," Organid ":" "," Summaryurl ":" "," Createtime ":" 2016-01-29 16:25:46 "," Createuserid ":" 0b8d60c9-c3b6-498f-a7f2-a28b7bf99232 "," CreateUser ":" Lanyang "," Updateuserid ":" 0b8d60c9-c3b6-498f-a7f2-a28b7bf99232 "," UpdateTime ":" 2016-01-29 16:25:46 "," UpdateUser ":" Lanyang "}]
Our ultimate goal is to transfer the JSON to the object
Get a params parameter as follows:
HttpServletRequest request = getcontext (). Getrequest (); = Request.getparameter ("params"); = Jsonarray.fromobject (params); // Read the array of strings first object[] o = Array.toarray (); // turn to an array of pairs like Jsonobject obj = Jsonobject.fromobject (o[0]); // then use Jsonobject to traverse a pair of images Shopgoodsprductys Shopgoodsprductys = (shopgoodsprductys) Obj.tobean (obj,shopgoodsprductys. Class); // Specifies the type of conversion, but still requires a forced conversion-successful
Front-end pass-through parameter formats such as:
var shopgoodsprductys = []; Shopgoodsprductys.push ({ "Suppliercode" :suppliercode, "p Roductname ":p Roductname, " Datahandelmethod ": Datahandelmethod, "ProductType" :p Roducttype, "YSCPCBJ" :YSCPCBJ, "Effectivetime" :effectivetime, "Invalidtime" Span style= "color: #000000;" >:invalidtime, status :status, "id" :id ...});
var params = json.stringify (shopgoodsprductys); $.ajax ({ ' POST ', data: {params:params}, Url:getbasepathurl (' zxxt/ Shopgoodsprductys.action?saveshopgoodsprductys= '), dataType:"JSON", success:function ( Result) { alert ("Operation succeeded"); }, error:function (XHR) { alert ("operation failed"); } } );
JSON to Bean Object