HarmonyOS 鸿蒙Next distributedKVStore存储数据报错
HarmonyOS 鸿蒙Next distributedKVStore存储数据报错
按照文档存储键值对,报错An unexpected error occurred.code is 401,message is Parameter error. The type of value must be ValueType.
/**
* 存储数据
* @param key string
* @param value Uint8Array | string | number | boolean
*/
put(key: string, value: Uint8Array | string | number | boolean) {
try {
kvStore?.put(key, value, (err) => {
if (err !== undefined) {
console.error(`Failed to put data. Code:${err.code},message:${err.message}`);
return;
}
console.info('Succeeded in putting data.');
})
} catch (e) {
let error = e as BusinessError;
console.error(`An unexpected error occurred. Code:${error.code},message:${error.message}`);
}
}
KVUtils.getInstance().put(`${mUserInfo.user_id}`, `${data}`)
更多关于HarmonyOS 鸿蒙Next distributedKVStore存储数据报错的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
根据报错,入参报错,可以检查下参数类型是否正确,
put(key,value)
:
- key支持string
- value支持Uint8Array、number 、 string 、boolean,Uint8Array、string 的长度不大于MAX_VALUE_LENGTH。
更多关于HarmonyOS 鸿蒙Next distributedKVStore存储数据报错的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html