js array of values ​​to pass background processing (JSON)

To pass an array of experience in the foreground to the background to go, if you have been spliced ​​with a string of words, I feel a little less easy to use in the project, with the thought pass arrays. My approach is to first save to pass an array of values, and then turn the array into JSON format spread to the background.
1, js codes:
var table = document.getElementById("gtable");     
var obj = "";
     var array = new Array();
     for(var i = 1;i<=9;i++){
         if(table.rows.cells[1].innerHTML != "" && table.rows.cells[1].innerHTML!=" "){
             obj = new Object();
             obj.num = table.rows.cells[0].innerHTML;
             obj.candidate = table.rows.cells[1].innerHTML;
             array.push(obj);
         }
     }
This is to get the value of the entire table inside.
Transmission values: textInfo: encodeURIComponent (JSON.stringify (array)), encodeURIComponent transcoding, to prevent back to Chinese garbled.
The most important thing is JSON.stringify (array) This array is converted into writing JSON format. First import json2.js, byhttps://github.com/douglascrockford/JSON-js/blob/master/json2.js
2, java codes
Object [] list = JSONUtils.getStringArray4Json (URLDecoder.decode (request.getParameter ( "textInfo"), "UTF-8"))); textInfo variable is transferred from the front.
JSONUtils.getStringArray4Json method:
/** *//**
* From parsing json array java string array
     * @param jsonString
     * @return
     */
    public static String[] getStringArray4Json(String jsonString){
        
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
        String[] stringArray = new String[jsonArray.size()];
        for( int i = 0 ; i<jsonArray.size() ; i++ ){
            stringArray = jsonArray.getString(i);
            
        }
        
        return stringArray;
    }
Object spooler first converted to an array of objects, and then through the array list
for (int j = 0; j < list.length; j++) {
                String textInfo = list[j].toString();
                Map textInfoMap = JSONUtils.getMap4Json(textInfo);
                String answerId = textInfoMap.get("num").toString();
                String cdate=textInfoMap.get("candidate ").toString(); 
               System.out.println(answerId+","+cdate );
            }
So that you can get the front desk pass over each value of the array. This method is also a reference written by someone else, learn from others, a detailed record of them before they go after their own forgotten

Reproduced in: https: //my.oschina.net/u/3055303/blog/878944

Intelligent Recommendation

Js way to pass array parameters to the background controller

Sharing a js method of passing array parameters to the background controller has a good reference value and I hope to help everyone. passes the arguments to the string, so to convert the array to a st...

JS uses the AJAX pass value to the background, the background returns a string processing

Previously used JS to get the JSON string generated by the background, then fill the SELECT, this time you need to re-get once. The goal here is that in an input box, enter a username, determine if it...

springMVC, foreground ajax pass JSON array parameters, how to receive background

Background sections: // json package used: com.alibaba.fastjson...

Use Ajax to pass the JSON array to MVC background front end

Use Ajax to pass the JSON array to MVC background front end Front -end code: Background code:...

More Recommendation

C # pass values ​​to the js

variable transmission: Pass value method:...

Javaweb foreground to pass values ​​to the background

First, ajax forwards the list collection to the background, the background springmvc receives JSON object and JSON string In the SpringMVC environment,@RequestBodyThe bold style receives a string of J...

How to pass values ​​to the checkbox in the background

How to pass the value to the checkbox in the background?????? Is there any direct pass to the array???...

Js get pass Chinese parameters background garbled processing

The second pass is because tomcat will automatically process once with iso-889-1, and then decode it with URLDecode....

JS pass the value to the background, special character processing problem

When you do a project, you encounter a special character escape problem, such as #, which will be ignored when you have submitted the background. Front end JS code: Existing bug: The user manually ent...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top