天天看点

Android studio 中Gson使用实例step2:使用Gson...

step1:在工程的build.gradle中添加依赖库

Android studio 中Gson使用实例step2:使用Gson...

step2:使用Gson...

1) 数组转json 字符串

Gson g = new Gson();
String jsonString = g.toJson(labelInfo.boundingBox);      

2) json字符串转数组

Gson gson = new Gson();
int [] rectValue = gson.fromJson(faceRectJson, new TypeToken<int []>() {
}.getType());          

3) 自定义的实体类:

Gson gson = new Gson();

Response<User> response1 = gson.fromJson(fileInfoJson, new TypeToken<Response<User>>() {
}.getType());