MMKV icon indicating copy to clipboard operation
MMKV copied to clipboard

Android使用mmkv取缓存后,对象里面的某个字段变成了 【��】

Open androidway opened this issue 1 year ago • 5 comments

Android使用mmkv取缓存后,对象里面的某个字段变成了 【��】,这个是什么原因呢?

### Tasks

androidway avatar Aug 27 '24 03:08 androidway

Without logs, it's impossible to know for sure. Please provide the necessary info as the issue template requires, otherwise this issue will be ignored and closed.

lingol avatar Aug 27 '24 03:08 lingol

取缓存调用:

public <T extends Parcelable> T getParcelable(String name, String key,Class<T> tClass) { MMKV mmkv = getMMKV(name); try { T t = mmkv.decodeParcelable(key, tClass); return t; }catch (Throwable e){ mmkv.remove(key); } return null; }

获取到的结果: {"employeeName":"", "employeeId":"��", "goodsCover":true, "remark":"", ……}

其中 employeeId字段内容成为��了。

androidway avatar Aug 27 '24 04:08 androidway

In that case, serialize your object into data and deserialize back to see if that employeeId is correct.

lingol avatar Aug 27 '24 06:08 lingol

正常使用没问题,现在就是不知道什么情况下会出现这个情况。 我这边目前也复现不了

androidway avatar Aug 27 '24 09:08 androidway

It's highly likely that it contains non Utf-8 characters.

lingol avatar Aug 27 '24 11:08 lingol

Closed due to inactive.

lingol avatar Sep 06 '24 01:09 lingol