Java???л??????л??????????
???????????? ???????[ 2012/8/14 10:16:17 ] ????????
????????????
<Person-array>
<Person>
<name>Jay</name>
<age>24</age>
</Person>
<Person>
<name>Tom</name>
<age>23</age>
</Person>
</Person-array>
????3??JSON???
//?ο?:http://www.cnblogs.com/hoojo/archive/2011/04/22/2025197.html
public class SerializeJSON {
public static void main(String[] args) {
SerializeJSON serializeJSON = new SerializeJSON();
serializeJSON.writeJSON();
serializeJSON.readJSON();
}
public void writeJSON(){
XStream xStream = new XStream(new JettisonMappedXmlDriver());
Person person = new Person("geniushehe"?? 16);
try {
FileOutputStream fos = new FileOutputStream("E:\json.js");
xStream.setMode(XStream.NO_REFERENCES);
xStream.alias("Person"?? Person.class);
xStream.toXML(person?? fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void readJSON(){
XStream xStream = new XStream(new JettisonMappedXmlDriver());
Person person = null;
try {
FileInputStream fis = new FileInputStream("E:\json.js");
xStream.setMode(XStream.NO_REFERENCES);
xStream.alias("Person"?? Person.class);
person = (Person)xStream.fromXML(fis);
System.out.println(person.getName());
System.out.println(person.getAge());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
????????????
{"Person":{"name":"geniushehe"??"age":16}}
??????
???·???
??????????????????
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