JSON to Bean Object

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.