2016-11-13 27 views
0

在我的Android应用程序中,Json供稿可能具有法语,德语和西班牙语特殊字符,如“马德里竞技对马拉加”。 Feed在浏览器中看到它们时正常工作,但在插入相同数据时,sqllite会显示未知字符。在其他帖子的专家对StackOverFlow的建议中,我在HttpConnections和InputStream中进行了这些更改以支持UTF-8,但它不起作用。我被告知sqllite支持UTF-8,不需要更改配置。我在做什么错?请帮忙。谢谢。Json供稿中的特殊字符在sqllite数据库中插入为未知字符

InputStream isC = null; 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     conn.setRequestProperty("Accept-Charset", "UTF-8"); 
     conn.setConnectTimeout(10000); 
     conn.setRequestMethod("GET"); 
     conn.setDoInput(true); 
     conn.setRequestProperty("Content-type", "application/json;charset=UTF-8"); 
     conn.connect(); 
     int response = conn.getResponseCode(); 
     isC = conn.getInputStream(); 
     JsonReader jsonReader = new JsonReader(new InputStreamReader(isC, "UTF-8")); 
     jsonReader.setLenient(true); 
     jsonReader.beginObject(); 

回答

0

您解码为UTF-8,它仅支持ASCII字符。

如果遇到非ASCII字符(á,ó,ú,í,é),则会出现奇怪的行为。

另外,请确保您要保存到数据库中的列支持Unicode - 在MsSql中,它需要是一个nvarchar字段。不知道SQLite等价物是什么...