ที่ปลายด้านหน้า:
1. หาก JSON ถูกแปลงจากวัตถุรายการคุณสามารถสำรวจ JSON และอ่านข้อมูลได้โดยตรง
2. หากคุณต้องการแปลงวัตถุรายการ front end เป็น JSON และส่งผ่านไปยังพื้นหลังและ Param เป็นพารามิเตอร์ของ AJAX การแปลงเป็นดังนี้:
var jsonstr = json.stringify (รายการ); var param = {}; param.jsonstr = jsonstr; ในพื้นหลัง:
1. แปลงสตริงเป็นรายการ (แปลง Str เป็นรายการ)
รายการ <t> list = new ArrayList <T> (); jsonArray jsonarray = jsonArray.fromObject (str); // แปลงสตริงเป็น json list = jsonarray.tolist (jsonarray, t); // t นี่คือคลาส <t>
2. แปลงรายการเป็น JSON
jsonArray json = jsonarray.fromobject (วัตถุ); string str = json.toString (); // แปลง JSON เป็นสตริง
เช่น:
1. รูปแบบรายการวัตถุคำตอบตามข้อมูลที่ป้อนโดยผู้ใช้หน้า
/ ** * @param คำตอบ * @param question_ids * @param ประเภท * @return */ รายการส่วนตัว <sersway> toanswerlist (String [] studentanswers, int [] question_ids, int [] ประเภท, int [] คะแนน) if (studenanswers! = null && question_ids! = null && types! = null && คะแนน! = null) {สำหรับ (int i = 0; i <studentanswers.length; i ++) {คำตอบ = คำตอบใหม่ (); String StudentAnswer = StudentAswers [i]; int type = types [i]; int question_id = question_ids [i]; คะแนน int = คะแนน [i]; คำตอบ SetQuestion_id (คำถาม _id); คำตอบ Setscore (คะแนน); คำตอบ SetStudenanswer (Studenanswer); answer.setType (ประเภท); ansterflist.add (คำตอบ); }} return answerlist; } / ** * แปลงสตริง JSON เป็นรายการ * @param props * @return * / รายการคงที่สาธารณะ <SERNERNA> ConververtAnsWerFormString (คำตอบสตริง) {ถ้า (คำตอบ == null || answer.equals ("")) คืน arrayList ใหม่ (); jsonArray jsonarray = jsonarray.fromobject (คำตอบ); รายการ <sunpers> list = (list) jsonarray.tocollection (jsonarray, answer.class); รายการคืน; - 2. สร้างสตริง JSON ไปยังรายการวัตถุคำตอบซึ่งสร้างขึ้นตามข้อมูลที่ป้อนโดยผู้ใช้ในหน้าไคลเอนต์
สตริงสาธารณะ getanswerstring (String [] studentanswers, int [] question_ids, int [] ประเภท, int [] คะแนน) {list list = toanswerlist (studenanswers, question_ids, ประเภท, คะแนน); jsonArray jsonarray = jsonarray.fromobject (รายการ); return jsonarray.toString (); -PS: นี่คือเครื่องมือออนไลน์ JSON ที่ใช้งานได้จริงสำหรับการอ้างอิงของคุณ:
การตรวจสอบรหัส JSON ออนไลน์การตรวจสอบความสวยงามและการจัดรูปแบบเครื่องมือ:
http://tools.vevb.com/code/json
เครื่องมือการจัดรูปแบบออนไลน์ JSON :
http://tools.vevb.com/code/jsonformat
เครื่องมือแปลง Mutual XML/JSON ออนไลน์:
http://tools.vevb.com/code/xmljson
JSON CODE การจัดรูปแบบออนไลน์/การตกแต่ง/การบีบอัด/แก้ไข/แปลงเครื่องมือ:
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