mirror of
https://github.com/Estom/notes.git
synced 2026-02-04 11:04:21 +08:00
Java内容重新整理删除过期的东西
This commit is contained in:
41
Java/JavaDemo/codedemo/json/gson/ArraySerialize.java
Normal file
41
Java/JavaDemo/codedemo/json/gson/ArraySerialize.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package cn.aofeng.demo.json.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* 数组的序列化。
|
||||
*
|
||||
* @author <a href="mailto:aofengblog@163.com">聂勇</a>
|
||||
*/
|
||||
public class ArraySerialize {
|
||||
|
||||
public void serialize(Object[] arr) {
|
||||
Gson gson = new Gson();
|
||||
System.out.println( gson.toJson(arr) );
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArraySerialize as = new ArraySerialize();
|
||||
|
||||
// 整型对象数组
|
||||
Integer[] intArr = new Integer[3];
|
||||
intArr[0] = 9;
|
||||
intArr[1] = 7;
|
||||
intArr[2] = 5;
|
||||
as.serialize(intArr);
|
||||
|
||||
// 字符串数组
|
||||
String[] names = new String[3];
|
||||
names[0] = "张三";
|
||||
names[1] = "李四";
|
||||
names[2] = "王五";
|
||||
as.serialize(names);
|
||||
|
||||
// 对象数组
|
||||
Person[] persons = new Person[2];
|
||||
persons[0] = new Person("小明", 10);
|
||||
persons[1] = new Person("马丽", 9);
|
||||
as.serialize(persons);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user