求助:我弄的类是这样的:
public class Test3 {
public String name;
public List numbers;
public List arrays;
}
生成json:
private void xObjToJson() {
List numbers = new ArrayList<>();
numbers.add(10);
numbers.add(20);
List arrays = new ArrayList<>();
arrays.add(new int[]{10,11});
arrays.add(new int[]{12,13,15});
arrays.add(new int[]{99});
Test3 test3 = new Test3("哈哈",numbers,arrays);
String json = JSON.toJSONString(test3);
Log.i(TAG, "xObjToJson: " + " " + json);
//这个地方没出问题
}
生成的结果: {"arrays":[[10,11],[12,13,15],[99]],"name":"哈哈","numbers":[10,20]}
解析JSON不知道该怎么弄,用JSON.parseObject(json, Test3.class);出错
import com.alibaba.fastjson.JSONObject;
public class Test {
public static void main(String[] args) {
String s = "{\"arrays\":[[10,11],[12,13,15],[99]],\"name\":\"哈哈\",\"numbers\":[10,20]}";
Test3 t = JSONObject.parseObject(s,Test3.class);
System.out.println(t);
}
}
结果不报错,你再试试
我这边测试之后并不会报错。。
使用alibaba的fastjson解析就好了