my json is shown below:
{
"status": "ok",
"count": 1,
"pages": 1,
"category": {
"id": 44,
"slug": "flex-print",
"title": "Flex Print",
"description": "Flex Print",
"parent": 7,
"post_count": 1
},
"posts": [
{
"id": 343,
"type": "post",
"slug": "nk-advertising",
"url": "https://btownmedia.com/2018/10/10/nk-advertising/",
"status": "publish",
"title": "NK Advertising",
"title_plain": "NK Advertising",
"content": "<p style=\"color: #7a6666; font-family: roboto-regular-webfont; font-size: 14px; line-height: 24px; margin: 0px; padding: 0px 0px 19px; width: 370px;\"><strong>Online advertisement:</strong> <em>Online advertisement on our website</em> means our basic service. Your business card or a visiting card sized advertisement is displayed on our website for pre-mentioned time frame.</p>\n<p style=\"color: #7a6666; font-family: roboto-regular-webfont; font-size: 14px; line-height: 24px; margin: 0px; padding: 0px 0px 19px; width: 370px;\"><strong>Personalized page:</strong> We offer you a personalized page, designed for your business with all the details of your business- linked with your advertisement that opens when clicked.</p>\n",
"excerpt": "<p>Online advertisement on our website means our basic service. Your business card or a visiting card sized advertisement is displayed on our website for pre-mentioned time frame.</p>\n",
"date": "2018-10-10 08:08:29",
"modified": "2018-10-10 08:08:29",
"categories": [
{
"id": 44,
"slug": "flex-print",
"title": "Flex Print",
"description": "Flex Print",
"parent": 7,
"post_count": 1
}
],
"tags": [],
"author": {
"id": 1,
"slug": "admin",
"name": "admin",
"first_name": "",
"last_name": "",
"nickname": "admin",
"url": "",
"description": ""
},
"comments": [],
"attachments": [
{
"id": 342,
"url": "https://btownmedia.com/nk/",
"slug": "nk",
"title": "nk",
"description": "",
"caption": "",
"parent": 343,
"mime_type": "image/png",
"images": {
"full": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"thumbnail": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-150x142.png",
"width": 150,
"height": 142
},
"medium": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"medium_large": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"large": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"rpggallery_admin_thumb": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"rpggallery_admin_large": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"rpg_gallery_admin_thumb": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-150x142.png",
"width": 150,
"height": 142
},
"rpg_gallery_thumb": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-150x142.png",
"width": 150,
"height": 142
},
"estore-featured-image": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"estore-product-grid": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-75x75.png",
"width": 75,
"height": 75
},
"estore-square": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"estore-slider": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"estore-medium-image": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
}
}
}
],
"comment_count": 0,
"comment_status": "open",
"thumbnail": "https://btownmedia.com/wp-content/uploads/2018/10/nk-150x142.png",
"custom_fields": {},
"thumbnail_size": "thumbnail",
"thumbnail_images": {
"full": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"thumbnail": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-150x142.png",
"width": 150,
"height": 142
},
"medium": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"medium_large": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"large": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"rpggallery_admin_thumb": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"rpggallery_admin_large": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"rpg_gallery_admin_thumb": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-150x142.png",
"width": 150,
"height": 142
},
"rpg_gallery_thumb": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-150x142.png",
"width": 150,
"height": 142
},
"estore-featured-image": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"estore-product-grid": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk-75x75.png",
"width": 75,
"height": 75
},
"estore-square": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"estore-slider": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
},
"estore-medium-image": {
"url": "https://btownmedia.com/wp-content/uploads/2018/10/nk.png",
"width": 230,
"height": 142
}
}
}
]
}
Post.java
public class Post {
private Integer id;
private String type;
private String slug;
private String url;
private String status;
private String title;
private String titlePlain;
private String content;
private String excerpt;
private String thumbnail;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitlePlain() {
return titlePlain;
}
public void setTitlePlain(String titlePlain) {
this.titlePlain = titlePlain;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getExcerpt() {
return excerpt;
}
public void setExcerpt(String excerpt) {
this.excerpt = excerpt;
}
public String getThumbnail() {
return thumbnail;
}
public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}
}
PostArtical.java
public class PostArtical {
private String status;
private Integer count;
private Integer pages;
private Category category;
private List<Post> posts = null;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Integer getPages() {
return pages;
}
public void setPages(Integer pages) {
this.pages = pages;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public List<Post> getPosts() {
return posts;
}
public void setPosts(List<Post> posts) {
this.posts = posts;
}
}
Category.java
public class Category {
private Integer id;
private String slug;
private String title;
private String description;
private Integer parent;
private Integer postCount;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getParent() {
return parent;
}
public void setParent(Integer parent) {
this.parent = parent;
}
public Integer getPostCount() {
return postCount;
}
public void setPostCount(Integer postCount) {
this.postCount = postCount;
}
}
MainActivity.java
//inside the onCreate method
onCreate method {
getRetrofitPostObject();}
//out side the onCreate Method
void getRetrofitPostObject() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(urlp)
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitObjectAPI service = retrofit.create(RetrofitObjectAPI.class);
Call<PostArtical> call = service.getPostDetails();
call.enqueue(new Callback<PostArtical>() {
@Override
public void onResponse(Response<PostArtical> response, Retrofit retrofit) {
try {
Log.d("Category", response.body().getCategory().getTitle());
Log.d("PostText", response.body().getPosts().get(0).getTitle());
List<Post> PostData = response.body().getPosts();
for (int i = 0; i < PostData.size(); i++) {
if (i == 0) {
text_id_1.setText("id : " + PostData.get(i).getId());
Log.d("Atrical[0]", String.valueOf(PostData.get(i).getId()));
Log.d("Atrical[title]", String.valueOf(PostData.get(i).getTitle()));
Log.d("Atrical[content]", String.valueOf(PostData.get(i).getContent()).replaceAll("(<[^>]+>)|(&[^;]+;)",""));
Log.d("Atrical[Excerpt]", String.valueOf(PostData.get(i).getExcerpt()).replaceAll("(<[^>]+>)|(&[^;]+;)",""));
Log.d("Atrical[image]", String.valueOf(PostData.get(i).getThumbnail()));
img = PostData.get(i).getThumbnail();
DownloadImageWithURLTask downloadTask = new DownloadImageWithURLTask(imageview);
downloadTask.execute(img);
// text_name_1.setText("title : " + StudentData.get(i).getTitle());
}
}
// text_id_1.setText("PostStatus : " + response.body().getStatus());
text_name_1.setText("PostCount : " + response.body().getCount());
text_marks_1.setText("PostPage : " + response.body().getPages());
} catch (Exception e) {
Log.d("onResponse", "There is an error");
e.printStackTrace();
}
}
@Override
public void onFailure(Throwable t) {
Log.d("onFailure", t.toString());
}
});
}
//out side the onCreate Method Download image:
private class DownloadImageWithURLTask extends AsyncTask<String, Void, Bitmap> { ImageView bmImage; public DownloadImageWithURLTask(ImageView bmImage) { this.bmImage = bmImage; } protected Bitmap doInBackground(String... urls) { String pathToFile = urls[0]; Bitmap bitmap = null; try { InputStream in = new java.net.URL(pathToFile).openStream(); bitmap = BitmapFactory.decodeStream(in); } catch (Exception e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return bitmap; } protected void onPostExecute(Bitmap result) { bmImage.setImageBitmap(result); } }
Comments
Post a Comment