Android 为什么我必须将编码的JSON响应重新编码到utf-8,以便将其保存到SQLite?
我使用UTF-8正确编码JSON响应,并尝试将响应字符串保存到SQLite表中 然后我注意到它没有正确保存并且已经?????非英语字符 我试图在保存之前修复编码Android 为什么我必须将编码的JSON响应重新编码到utf-8,以便将其保存到SQLite?,android,json,sqlite,encoding,utf-8,Android,Json,Sqlite,Encoding,Utf 8,我使用UTF-8正确编码JSON响应,并尝试将响应字符串保存到SQLite表中 然后我注意到它没有正确保存并且已经?????非英语字符 我试图在保存之前修复编码 @Override public void onResponse(String response) { SavedResponse mysavedresponse = new SavedResponse(); JSONObject j = n
@Override
public void onResponse(String response)
{
SavedResponse mysavedresponse = new SavedResponse();
JSONObject j = null;
int resp_count = (int) db.getResponsesCount();
try {
//String MyResponse = fixEncodingUnicode(response);
//CHECK IF IT IS NEW RESPONSE
if(resp_count>0)
{
mysavedresponse = db.getMySavedResponse();
response = mysavedresponse.getSavedresponse();
}else
{
**db.AddResponse(fixEncodingUnicode(response));**
db.close();
}
j = new JSONObject(response);
}catch (JSONException e) {
e.printStackTrace();
}
此外,如果我以初始值添加db.deletesponses,那么如果我注释掉我再次得到的db.deletesponses,它就会工作
为什么如果我的响应被正确编码,我可以在调试时看到它,当它被保存在sqlite表中时,它就被弄乱了
谢谢您的JSON对象是否需要像SQLite中的JSON一样存储?只对其进行base64编码会更容易,因为您不必担心字符集与ASCII编码的所有字符发生冲突。可能会出现重复,没有人知道您的JSON是否真的正确编码,或者您的
fixEncodingUnicode
的功能。我检查了它,它看起来正常,并且是一个有效的JSON