In front:
1. If JSON is a list object conversion, you can traverse JSON directly and read the data.
2. If it is necessary to convert the front End list object to JSON to the background, param is an ajax parameter, then the conversion looks like this:
var jsonstr = json.stringify (list);
var param= {};
PARAM.JSONSTR=JSONSTR;
In the background:
1. Convert String to list (str conversion to list)
list<t> list = new arraylist<t> ();
Jsonarray Jsonarray = Jsonarray.fromobject (str);//convert string to JSON
list = jsonarray.tolist (jsonarray,t); Here's T is class<t>
2. Convert list to JSON
Jsonarray JSON = Jsonarray.fromobject (object);
String str = json.tostring ();//convert JSON to string
eg
1. form a list of Answer objects based on the information entered by the page user
/** * @param answers * @param question_ids * @param types * @return/private list<answer> Toanswerlist (string[] studenanswers, int[] question_ids, int[] types,int[] scores) {list<answer> Answer
List = new arraylist<answer> (); if (studenanswers!=null && question_ids!= null && types!= null&& scores!= null) {for (int i = 0; i < studenanswers.length;
i++) {Answer Answer = new Answer ();
String studenanswer = studenanswers[i];
int type = Types[i];
int question_id = Question_ids[i];
int score = Scores[i];
ANSWER.SETQUESTION_ID (question_id);
Answer.setscore (score);
Answer.setstudenanswer (Studenanswer);
Answer.settype (type);
Answerlist.add (answer);
} return answerlist; /** * Converts a JSON string to list * @param props * @return/Public Static list<answer> converanswerformstring (String Answer) {if (Answer = = NULL | | answer.equals (")) RET
Urn new ArrayList ();
Jsonarray Jsonarray = Jsonarray.fromobject (answer);
list<answer> list = (list) jsonarray.tocollection (Jsonarray, Answer.class);
return list;
}
2. Generate a JSON string from a list of Answer objects, based on information entered by the client page user
Public String getanswerstring (string[] studenanswers, int[] question_ids,
int[] types,int[] scores) {
List List = Toanswerlist (Studenanswers, Question_ids,
types, scores);
Jsonarray Jsonarray = jsonarray.fromobject (list);
return jsonarray.tostring ();
}