我在mangal.tff中有一个带字体的JSON。需要解析它,并应显示其字体textview,但textviews中的字体是不可读的格式。
我的Android代码
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("data");
for(int i = 0; i<jsonArray.length(); i++){
String title = newsValue.getString("title");
String imageresource = newsValue.getString("image");
String description = newsValue.getString("description");
NewsData newsData = new NewsData();
newsData.setDesc(description);
newsData.setTitle(title);
newsData.setNewsImage(imageresource);
newsDatas.add(newsData)
}
newsAdapter.notifyDataSetChanged();
答案 0 :(得分:2)
您的Json解析不正确
将字体类型设置为textview
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/yourFont.TTF");
试试这个,
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("data");
for (int i =0;i<jsonArray.length();i++) {
JSONObject obj=jsonArray.getJSONObject(i);
String title = obj.getString("title");
String imageresource = obj.getString("image");
String description = obj.getString("description");
NewsData newsData = new NewsData();
newsData.setDesc(description);
newsData.setTitle(title);
newsData.setNewsImage(imageresource);
newsDatas.add(newsData);
}
newsAdapter.notifyDataSetChanged();