Java?е?JSON????????
???????????? ???????[ 2014/9/15 11:29:39 ] ??????????????? Java ???
????????????????????????JSON?????????????????????????AJAX?????JSON????????????java??????У?????JSON??????????
?????????????????JSON?????jar????JSON-lib.jar??json.jar?????????????JSON-lib.jar??
????jar????????£?
????json-lib-2.4-jdk15.jar???????JAR??.rar
???????JSON-lib.jar??????????jar????
????commons-lang.jar
????commons-beanutils.jar
????commons-collections.jar
????commons-logging.jar
????ezmorph.jar
????json-lib-2.2.2-jdk15.jar
???????????
????JSON?????key-value?????????key?????????value??????????????JSONArray??JSONObject.
????JSONArray:[]?????????????????????????????????????JSON
????JSONObject:{}?????JSON??
??????????????????????????????
???????????JSON??????????[]??{}???ж?????????????????????????????????????д????ò??淶???
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class JSONTest {
public static void main(String[] args) {
JSONObject container1 = new JSONObject();
container1.put("ClassName"?? "???????");
System.out.println(container1.toString());
JSONArray className = new JSONArray();
className.add("???????");
container1.put("className"?? className);
System.out.println(container1.toString());
JSONObject classInfo = new JSONObject();
classInfo.put("stuCount"?? 50);
classInfo.put("leader"?? "rah");
container1.put("classInfo"?? classInfo);
System.out.println(container1);
JSONObject ClassInfo = new JSONObject();
JSONArray stuCount = new JSONArray();
stuCount.add(50);
JSONArray leader = new JSONArray();
leader.add("rah");
ClassInfo.put("stuCount"?? stuCount);
ClassInfo.put("leader"?? leader);
container1.put("ClassInfo"?? ClassInfo);
System.out.println(container1);
JSONArray students = new JSONArray();
JSONObject studentOne = new JSONObject();
studentOne.put("name"?? "??????");
studentOne.put("sex"?? "??");
studentOne.put("age"?? 12);
studentOne.put("hobby"?? "java develop");
JSONObject studentTwo = new JSONObject();
studentTwo.put("name"?? "?????");
studentTwo.put("sex"?? "??");
studentTwo.put("age"?? 13);
studentTwo.put("hobby"?? "C/C++ develop");
students.add(studentOne);
students.add(studentTwo);
container1.put("students"?? students);
System.out.println(container1);
JSONArray Students = new JSONArray();
JSONObject StudnetOne = new JSONObject();
JSONArray name1 = new JSONArray();
name1.add("??????");
JSONArray sex1 = new JSONArray();
sex1.add("??");
JSONArray age1= new JSONArray();
age1.add("12");
JSONArray hobby1 = new JSONArray();
hobby1.add("java develop");
StudnetOne.put("name"?? name1);
StudnetOne.put("sex"?? sex1);
StudnetOne.put("age"?? age1);
StudnetOne.put("hobby"?? hobby1);
JSONObject StudnetTwo = new JSONObject();
JSONArray name2 = new JSONArray();
name2.add("?????");
JSONArray sex2 = new JSONArray();
sex2.add("??");
JSONArray age2= new JSONArray();
age2.add("13");
JSONArray hobby2 = new JSONArray();
hobby2.add("C/C++ develop");
StudnetTwo.put("name"?? name2);
StudnetTwo.put("sex"?? sex2);
StudnetTwo.put("age"?? age2);
StudnetTwo.put("hobby"?? hobby2);
Students.add(StudnetOne);
Students.add(StudnetTwo);
container1.put("Students"?? Students);
System.out.println(container1);
JSONArray teachers = new JSONArray();
teachers.add(0??"?????");
teachers.add(1??"????? ");
container1.put("teachers"?? teachers);
System.out.println(container1);
JSONArray Teachers = new JSONArray();
JSONObject teacher1 = new JSONObject();
teacher1.put("name"?? "С÷");
teacher1.put("introduce"??"????????????");
JSONObject teacher2 = new JSONObject();
teacher2.put("name"?? "С??");
teacher2.put("introduce"??"??????????????");
Teachers.add(0??teacher1);
Teachers.add(1??teacher2);
container1.put("Teachers"?? Teachers);
System.out.println(container1);
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11