Android studio 中Gson使用实例

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


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());


猜你喜欢

转载自blog.csdn.net/whunamikey/article/details/80928375