導航:首頁 > 編程語言 > 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對象相關的資料

熱點內容
文件系統pdf 瀏覽:762
原神安卓區服什麼意思 瀏覽:34
貝殼app怎麼線上發布 瀏覽:157
如何挑選安卓系統機頂盒 瀏覽:53
安卓快充使用有什麼注意事項 瀏覽:909
黑馬程序員的雲計算網課 瀏覽:946
endnotestyle文件夾怎麼導入 瀏覽:460
講解少兒編程演講會開頭 瀏覽:424
思科交換機基礎命令 瀏覽:497
便簽可以設置加密嗎 瀏覽:339
免費漫畫app怎麼看書 瀏覽:27
華為筆記本電腦怎麼安裝抖音app 瀏覽:412
阿里雲國際版試用的伺服器怎麼搞 瀏覽:895
java正則表達式工具 瀏覽:160
oa伺服器怎麼設置ftp 瀏覽:10
安卓如何安裝obb 瀏覽:442
QQ聊天記錄journal文件夾 瀏覽:118
蘋果公司雲伺服器地址 瀏覽:85
加密記事本手機 瀏覽:437
汽車壓縮機變頻閥 瀏覽:95