프론트 엔드 :
1. JSON이 목록 객체에서 변환되면 JSON을 직접 통과하고 데이터를 읽을 수 있습니다.
2. 프론트 엔드 목록 객체를 JSON으로 변환하고 배경으로 전달 해야하는 경우 PARAM은 AJAX의 매개 변수입니다. 변환은 다음과 같습니다.
var jsonstal = json.stringify (list); var param = {}; param.jsonstal = jsonst; 백그라운드에서 :
1. 문자열을 목록으로 변환 (str로 변환)
목록 <t> list = new ArrayList <t> (); jsonarray jsonarray = jsonarray.fromobject (str); // 문자열 변환 JSON List = jsonArray.tolist (jsonArray, t); // 여기에 class <t>입니다.
2. 목록을 JSON으로 변환하십시오
jsonarray json = jsonarray.fromobject (Object); String str = json.tostring (); // json을 문자열로 변환합니다
예 : :
1. 페이지 사용자가 입력 한 정보를 기반으로 답변 개체 목록을 작성합니다.
/ ** * @param resong * @param question_ids * @param type * @return */ private list <sonswer> toanswerlist (string [] studentAnswers, int [] Question_Ids, int [] type, int [] scores) {list> answerd> new arrayList <answer> (); if (studenanswers! = null && question_ids! = null && type! = null && scores! = null) {for (int i = 0; i <windentAnswers.length; i ++) {답변 = 새 답변 (); String StudentAnswer = StudentAnswers [i]; int 유형 = 유형 [i]; int question_id = Question_ids [i]; int score = 점수 [i]; 답변 .setquestion_id (question_id); 답변 .setscore (점수); 답변 .setstudenanswer (Studenanswer); 답변 .setType (type); AnswerList.Add (답변); }} return answerlist; } / ** * JSON 문자열을 목록으로 변환 * @param props * @return * / public static list <songre> convertAnswerFormString (string answer) {if (답 == null || answer.equals ( "")) new arrayList ()를 반환합니다. jsonarray jsonarray = jsonarray.fromobject (답); List <songre> list = (list) jsonarray.tocollection (jsonarray, answer.class); 반환 목록; } 2. 클라이언트 페이지에서 사용자가 입력 한 정보를 기반으로 생성 된 답변 개체 목록에 JSON 문자열을 생성합니다.
public String getAnswerstring (String [] StudentAnswers, int [] Question_Ids, int [] type, int [] scores) {list list = toanswerlist (Studenanswers, Question_ID, 유형, 점수); jsonarray jsonarray = jsonarray.fromobject (list); return jsonarray.tostring (); }추신 : 참조를위한 몇 가지 실용적인 JSON 온라인 도구는 다음과 같습니다.
온라인 JSON 코드 검증, 검사, 미화 및 서식 도구 :
http://tools.vevb.com/code/json
JSON 온라인 서식 도구 :
http://tools.vevb.com/code/jsonformat
온라인 XML/JSON 상호 전환 도구 :
http://tools.vevb.com/code/xmljson
JSON 코드 온라인 서식/미화/압축/편집/변환 도구 :
http://tools.vevb.com/code/jsoncodeformat
온라인 JSON 압축/탈출구 :
http://tools.vevb.com/code/json_yasuo_trans
C 언어 스타일/HTML/CSS/JSON 코드 서식 및 미화 도구 :
http://tools.vevb.com/code/ccode_html_css_json