java中json字符串轉(zhuǎn)對象 java怎么樣將字符串轉(zhuǎn)換成json數(shù)組對象?
java怎么樣將字符串轉(zhuǎn)換成json數(shù)組對象?1. 需要JSON相關(guān)的jar包2。設(shè)置JSON格式字符串:字符串STR=“{”student“:[{”name“:”Leilei“,”age“:23},
java怎么樣將字符串轉(zhuǎn)換成json數(shù)組對象?
1. 需要JSON相關(guān)的jar包
2。設(shè)置JSON格式字符串:
字符串STR=“{”student“:[{”name“:”Leilei“,”age“:23},{”name“:”leilei02“,”age“:23}]}“
3。創(chuàng)建相應(yīng)的類:
public class studentlist{
list<student> student
public list<student> student(){
return student
}
public void setStudent(list<student> student){這個學(xué)生=student
}
}
公共類student{
私有字符串名
私有intage
//private StudentClass StudentClass
public String getName(){
return name
}
public void setName(String name){這個名字=name
}
public int getAge(){
return age
}
public void setAge(int age){這個年齡=4. 測試程序
導(dǎo)入java.util.List
導(dǎo)入網(wǎng)址:org.codehaus.jackson. map.ObjectMapper對象映射器
json字符串轉(zhuǎn)javamap?
我們需要將JSON字符串轉(zhuǎn)換為net.sf.json文件. jsonobject對象。在Java中,可以完成從JSON字符串到map的轉(zhuǎn)換。
1. 將數(shù)組轉(zhuǎn)換為JSON:String[]arr={“ASD”、“DFGD”、“ASD”、“234”}jsonarray=JSONArray.fromObject(阿里爾)系統(tǒng)輸出打?。╦sonarray)
2。對象轉(zhuǎn)換為JSON:userinfo user=new userinfo(1001,“Zhang San”)jsonarray jsonarray=JSONArray.fromObject(用戶)系統(tǒng)輸出打?。╦sonarray)
3,使用jsonobject對象:Map