今天解析后端数据时,发现了这个报错:Expected BEGIN_OBJECT but was STRING at
看来是自己哪儿解析错误了。
因为数据的特殊性,后端返回的Json串里面可能还会有Json数据,可能嵌套了三次层,
例如:
{"info":{"clientMsgId":"ebc5018f-b2bd-4c87-a662-5bcf11dd3843","content":"{\"inviteId\":159,\"meetingInfo\":{\"ownerAvatar\":\"https://cdn.dev.utown.io/i/20220528/0/1/b/01b020f1d5e043a886a20a6fcdf6b742.png\",\"kicked\":false,\"secret\":\"\",\"ownerId\":1000164,\"roomId\":1000556,\"needSecret\":false,\"remindTime\":0,\"ownerName\":\"24591417\",\"screenShareSetting\":0,\"hasMeetingFile\":false,\"meetingCode\":\"100003\",\"name\":\"啧啧额啧啧爷爷\",\"closeCameraWhenJoin\":false,\"startTime\":1656761474000,\"endTime\":1656765074000,\"id\":270,\"closeMicWhenJoin\":false,\"status\":0}}","contentType":1023,"conversationId":"f72c48dbd209486f95f8667e134bba28","msgSeq":393,"partner":{"userAvatar":"https://cdn.dev.utown.io/i/20220528/0/1/b/01b020f1d5e043a886a20a6fcdf6b742.png","userFace":"","userName":"24591417","userRelation":"STRANGER"},"receiverId":1000164,"senderId":1000164,"sendingState":"NONE","sessionType":0,"timestamp":1656758051949}}
content里面是一个json,解析出来,发现里面还有个meetinfo的json数据,然后在我解析的时候,就没怎么注意,就直接想的是默认这俩都是String类型嘛,先拿出来,再解析就是了,于是问题就出在这里,他是一个JsonObject对象,不是String!!
所以在实体类里
data class IMMeetJsonInfo( var inviteId:Int?, var meetingInfo:JsonObject? )
把meetInfo类型改成JsonObject就行了!!!