Public static void main (String[] args) {string studentjson= "{\" username\ ": \" Xiaoming\ ", \" age\ ": 20,\" desc\ ": \" good student \ "}"; string studentjson2= "{\" username\ ": \" xiaohong\ ", \" age\ ": 20,\" desc\ ": \" good student \ "}"; String[] json={studentjson,studentjson2}; //student st= ( Student) json2bean (studentjson, student.class); jsonarray jsonarray=jsonarray.fromobject (JSON);//json objects hold a lot of student data for ( Object obj:jsonarray) { student st= (Student) json2Bean ( ((Jsonobject) obj). ToString (), student.class); System.out.println (St.getusername () + ":" +st.getdesc ()); }} public static object json2bean (STRING JSON,CLASS CLA) {JSONObject Jsonobject=jsonobject.fromobjeCT (JSON); Return jsonobject.tobean (JSONOBJECT, CLA);}
Using the Json-lib framework, you can convert the foreground JSON object into a Java object, you need the following jar package, you can put the JSON data structure of multiple Java objects in the database, the use of Jsonarray into a JSON array, It then iterates through the array to get the Java object corresponding to each JSON data, and calls Jsonobject's Tobean method to get the object instance
JSON object to convert Java object