導航:首頁 > 編程語言 > java字元串轉換成json對象

java字元串轉換成json對象

發布時間:2025-02-05 12:21:09

『壹』 怎樣從java後台獲取json字元串並轉換為json對象輸出

使用json-lib.jar這個工具x0dx0apublic String getJson(Object obj){x0dx0a JSONObject json;x0dx0a json = JSONObject.fromObject(obj);x0dx0a return json.toString();x0dx0a}x0dx0a使用jquery來處理jsonx0dx0a//轉換為json數據 datas可以用ajax從後台獲取上面getJson中的數據x0dx0avar jsonDatas = eval("(" + datas + ")");x0dx0a //循環遍歷數據x0dx0ajQuery.each(jsonDatas, function(item) {x0dx0a//循環x0dx0a});

『貳』 java 含有數組的字元串怎麼轉化為json對象

1、需要json的相關jar包

2、設置json格式字元串:

String str="{\"student\":[{\"name\":\"leilei\",\"age\":23},{\"name\":\"leilei02\",\"age\":23}]}";

3、建立相應的類:

public class StudentList {
List<Student> student;
public List<Student> getStudent() {
return student;
}

public void setStudent(List<Student> student) {
this.student = student;
}
}

public class Student {
private String name;
private int age;
//private StudentClass studentClass;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

『叄』 java中字元串怎麼轉json

string類型如果要轉換成json的話,就需要寫成這樣的形式,如下:x0dx0aString jsonStr ="{'id':ཇ','parentId':'root','refObj':{'existType':'exist','deptType':'emp','treeNodeType':'dept'}}";x0dx0a JSONObject jsonObj = new JSONObject(jsonStr);x0dx0a JSONObject refObj = new JSONObject(jsonObj.getString("refObj"));x0dx0a String existType = refObj.getString("existType");x0dx0a System.out.println(existType);x0dx0ajar使用的是org.json.jar

閱讀全文

與java字元串轉換成json對象相關的資料

熱點內容
資料庫查詢系統源碼 瀏覽:617
php5314 瀏覽:358
完美國際安裝到哪個文件夾 瀏覽:669
什麼app可以掃一掃做題 瀏覽:540
程序員編碼論壇 瀏覽:924
淘點是什麼app 瀏覽:660
中國高等植物pdf 瀏覽:454
51單片機時間 瀏覽:182
後台如何獲取伺服器ip 瀏覽:267
單片機流水燈程序c語言 瀏覽:235
程序員第二職業掙錢 瀏覽:240
運行里怎麼輸入伺服器路徑 瀏覽:843
pythonstepwise 瀏覽:510
劉一男詞彙速記指南pdf 瀏覽:66
php認證級別 瀏覽:370
方舟編譯啥時候推送 瀏覽:1012
php手機驗證碼生成 瀏覽:677
哲學思維pdf 瀏覽:17
凌達壓縮機有限公司招聘 瀏覽:535
weblogic命令部署 瀏覽:39