0

//json code for news.org api

"source": {
    "id": "the-hindu",
    "name": "The Hindu"
    },
    "author": "",
    "title": "Questionable remedy: on the National Medical Commission Bill"``,
    "description": "Key sections of the National Medical Commission Bill need a rethink",
    "url": "http://www.thehindu.com/opinion/editorial/questionable-remedy/article22354009.ece",
    "urlToImage": "http://www.thehindu.com/static/theme/default/base/img/og-image.jpg",
    "publishedAt": null
    },
    -{
    -"source": {
    "id": "the-hindu",
    "name": "The Hindu"
    },
    "author": "",
    "title": "On the ledger: on fiscal consolidation",
    "description": "Expenditure data underline the government’s challenge on fiscal consolidation",
    "url": "http://www.thehindu.com/opinion/editorial/on-the-ledger/article22354014.ece",
    "urlToImage": "http://www.thehindu.com/static/theme/default/base/img/og-image.jpg",
    "publishedAt": null
    }

    }
    }
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • see this example https://www.learn2crack.com/2013/11/listview-from-json-example.html – Ameer Jan 03 '18 at 11:12
  • Ok, we have the json, but how about the code you (should) have already developed? What are the errors you are facing? – Leonardo Alves Machado Jan 03 '18 at 11:13
  • Seems to me you've done nothing on Android side. If you've, share your code and if not, I suggest you read upon Retrofit or Volley. There are countless tutorials on YouTube to achieve what you desire. – Nero Jan 03 '18 at 11:25
  • Did you really expect someone to write the code for you? This is not the right place then. – Rohit5k2 Jan 03 '18 at 11:33

1 Answers1

0

NB: Current response you posted is wrong, corrected to follow (not same , its example)

{
    "source": {
            "id": "the-hindu",
            "name": "The Hindu"
        },
    "author": "",
    "title": "Questionable remedy: on the National Medical Commission Bill",
    "description": "Key sections of the National Medical Commission Bill need a rethink",
    "url": "http://www.thehindu.com/opinion/editorial/questionable-remedy/article22354009.ece",
    "urlToImage": "http://www.thehindu.com/static/theme/default/base/img/og-image.jpg",
    "publishedAt": null
}   

Add Following POJO CLASS

POJO GET

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Get {

@SerializedName("source")
@Expose
private Source source;
@SerializedName("author")
@Expose
private String author;
@SerializedName("title")
@Expose
private String title;
@SerializedName("description")
@Expose
private String description;
@SerializedName("url")
@Expose
private String url;
@SerializedName("urlToImage")
@Expose
private String urlToImage;
@SerializedName("publishedAt")
@Expose
private Object publishedAt;

public Source getSource() {
return source;
}

public void setSource(Source source) {
this.source = source;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

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 String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getUrlToImage() {
return urlToImage;
}

public void setUrlToImage(String urlToImage) {
this.urlToImage = urlToImage;
}

public Object getPublishedAt() {
return publishedAt;
}

public void setPublishedAt(Object publishedAt) {
this.publishedAt = publishedAt;
}}

And Add Source POJO

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Source {

@SerializedName("id")
@Expose
private String id;
@SerializedName("name")
@Expose
private String name;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

Then on function call, you can get Get.title as title and Get.description as the description.

Then you can pass description as intent.putString("description",Get.description)

Subin Babu
  • 1,515
  • 2
  • 24
  • 50