我在应用程序中使用volley和JSON来增强mysql的数据,并在我的应用程序中显示。
我的数据库有三个字段:图像名-发布者,我的发布者字段是波斯语,应该是UTF-8。
这是我的代码:
//This method will parse json data
private void parseData(JSONArray array) {
for (int i = 0; i < array.length(); i++) {
//Creating the superhero object
SuperHero superHero = new SuperHero();
JSONObject json = null;
try {
//Getting json
json = array.getJSONObject(i);
//Adding data to the superhero object
superHero.setImageUrl(json.getString("image"));
superHero.setName(json.getString("name"));
superHero.setPublisher(json.getString("publisher").getBytes("ISO-8859-1"), "UTF-8");
} catch (JSONException e) {
e.printStackTrace();
}
//Adding the superhero object to the list
listSuperHeroes.add(superHero);
}
//Notifying the adapter that data has been added or changed
adapter.notifyDataSetChanged();
}如您所见,im使用getByte将其转换为utf-8,但这一行有如下错误:
Exception:java.io.UnsupportedEncodingException未处理的
我对此很不满意
我该怎么办??
非常感谢
发布于 2016-01-04 16:19:06
尝试使用字符串构造函数来转换UTF-8字符:
String publisher = new String(json.getString("publisher").getBytes("ISO-8859-1"), "UTF-8");同样,问题可能来自于给定的编码"ISO-8859-1“文档 / 文档。
https://stackoverflow.com/questions/34594868
复制相似问题