HarmonyOS 3.1/4 版本 多层json字符串如何解析?不想要一层对象挨个转换那种
HarmonyOS 3.1/4 版本 多层json字符串如何解析?不想要一层对象挨个自己new个对象转换那种,每一层创建个实体类太难受了
{"data":{"curPage":2,"datas":[{"adminAdd":false,"apkLink":"","audit":1,"author":"郭霖","canEdit":false,"chapterId":409,"chapterName":"郭霖","collect":false,"courseId":13,"desc":"","descMd":"","envelopePic":"","fresh":false,"host":"","id":27730,"isAdminAdd":false,"link":"https://mp.weixin.qq.com/s/CdkCT0CI5PGGLAtYIlalzQ","niceDate":"2023-12-14 00:00","niceShareDate":"1天前","origin":"","prefix":"","projectLink":"","publishTime":1702483200000,"realSuperChapterId":407,"selfVisible":0,"shareDate":1703035898000,"shareUser":"","superChapterId":408,"superChapterName":"公众号","tags":[{"name":"公众号","url":"/wxarticle/list/409/1"}],"title":"Android的MVI架构更佳实践之单元测试","type":0,"userId":-1,"visible":1,"zan":0}],"offset":20,"over":false,"pageCount":749,"size":20,"total":14980},"errorCode":0,"errorMsg":""}
解析成对象对吧
不包括泛型用Gson很简单
如果包括泛型就比较麻烦,看起来只能使用反射逐层赋值了
似乎很简单,但是各JSON库却都没有实现
PS.如果不是解析成对象,很简单,在GJson下用