Reputation: 83
I had a JSON with font in mangal.tff. need to parse its and should display with its fonts textview but the fonts in textviews are in unreadable format.
my code for 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();
Upvotes: 0
Views: 1070
Reputation: 3348
Your Json parsing not correct
Set the font type to textview
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/yourFont.TTF");
Try this,
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();
Upvotes: 2