Page pass JSON object, background parsing

Source: Internet
Author: User

Components used foreground component: Json2.js from http://www.json.org/js.html background components: Json-lib-2.2.2-jdk15.jar

Foreground code 1 generates a list of JSON objects by page and then converts them into strings
Generate JSON object to String function Maketsjsonparam () {var tslist = new Array (); var ts = {' tn_id ': ', ' tn_trainsortie ': ', ' tn_takeofftime ': ', ' tn_landingtime ': ', ' tn_commander ': ', ' Tn_calendar ':  ''};  var List1 = $ (". Flightid");  var List2 = $ (". Tn_trainsortie");  var list3 = $ (". Tn_takeofftime");  var list4 = $ (". Tn_landingtime");//var LIST5 = $ (". Tn_realitylandingtime");  var List6 = $ (". Tn_commander");//var list7 = $ (". Tn_mechanician");//var List8 = $ (". Tn_notes");  var List9 = $ (". Tn_calendar");  alert (list1.length);  for (Var i=0;i<list1.length;i++) {ts = {};  ts.tn_id = List1[i].value;  Ts.tn_trainsortie = List2[i].value;  Ts.tn_takeofftime = List3[i].value;  Alert (list3[i].value) ts.tn_landingtime= list4[i].value;//ts.tn_realitylandingtime= list5[i].value;  ts.tn_commander= list6[i].value;//ts.tn_mechanician= list7[i].value;//ts.tn_notes= list8[i].value;   Ts.tn_calendar= List9[i].value;  Tslist[i] = ts;  } var str = json.stringify (tslist); return str;}
2 Submit the processed JSON string to the background
  Pass the JSON string to background function Savealltrainsortie () {var str = Maketsjsonparam ();//alert (str) var htmlstr = "1"; $.ajax ({         URL: '.. /train/savealltrainferrysortie.do ',            //url: ' ${ctx}/index.jsp ',            cache:false,            type: ' Post ',            async: False,          dataType: ' html ',                data:{             trainsortieliststr:str,          contentType: "application/ X-www-form-urlencoded;charset=utf-8 "            },            success:function (HTML) {                //alert (" HTML: "+html)                Htmlstr = html;           }        })      return HTMLSTR/    *  if (htmlstr==1) {     alert ("Save succeeded");     } */}

Background Code 1 parses the string into a Java object after processing.
public void Savealltrainferrysortie (HttpServletRequest request,httpservletresponse response) {String Trainsortieliststr = Request.getparameter ("Trainsortieliststr"); Jsonarray array = jsonarray.fromobject (TRAINSORTIELISTSTR); for (int i=0;i<array.size (); i++) {map ts= (map) array.get (i); String tn_id = "" +ts.get ("tn_id");  String Tn_trainsortie = "" +ts.get ("Tn_trainsortie"); String tn_takeofftime = "" +ts.get ("Tn_takeofftime");  String tn_landingtime = "" +ts.get ("Tn_landingtime"); String tn_realitylandingtime = "" +ts.get ("Tn_realitylandingtime"); String Tn_commander = "" +ts.get ("Tn_commander");//string Tn_mechanician = "" +ts.get ("Tn_mechanician");//string Tn_ Notes = "" +ts.get ("tn_notes"); String Tn_calendar = "" +ts.get ("Tn_calendar"); Trainsoriteferryservice.savetrainsortie (tn_id, Tn_trainsortie, Tn_  Takeofftime, Tn_landingtime, Tn_commander, Tn_calendar);              }try {response.setcharacterencoding ("UTF-8");              PrintWriter pw = Response.getwriter (); Pw.write ("1");             Pw.flush ();          Pw.close ();          } catch (IOException e) {e.printstacktrace (); }  }




Page pass JSON object, background parsing

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.