Question: Please help with a function in java dealing with json pulling and parse data. Thanks ~+~+~+~+~+~+~+~+INTRO+~+~+~+~+~+~+~+~ You are going to be building one function ~+~+~+~+~+~+~+~+CODE

Please help with a function in java dealing with json pulling and parse data. Thanks

~+~+~+~+~+~+~+~+INTRO+~+~+~+~+~+~+~+~

You are going to be building one function

~+~+~+~+~+~+~+~+CODE STRUCTURE+~+~+~+~+~+~+~+~

public String buildNewsCall(boolean topHeadlines, String newsSource, String desiredContent, int pageNumber, String apiKey) { /* YOUR CODE HERE */

String url = "", excerpt = "", jsonData = ""; String headlines = "";0 if(topHeadlines == false){headlines = "everything";} else{headlines = "top-headlines";} jsonData = readURL( "https://newsapi.org/v2/" + headlines + "?sources=" + newsSource + "&q=" + desiredContent + "&page=" + pageNumber + "&apiKey=" + apiKey ); /* YOUR CODE HERE */

return buildTweet(url, excerpt); }

takes in several parameters which will allow you to build your API call. After it builds the call, then it will make it, and parse the data. It will isolate the data into a string called url, and a string called excerpt. After doing this, it will call the method buildTweet().

~+~+~+~+~+~+~+~+DETAILED EXPLANATION~+~+~+~+~+~+~+~+

Since the API we are using (NewsAPI) is the pathway to all of our sports news sources, you only need to write one method. Every single news source will be structured and organized the exact same way, so you don't have to worry about changing depending on the news source.

Like in the tutorial I gave you for JSONObjects, you are going to pull data out of a JSONObject and boil it down to the url and excerpt.

Open this link to see the structure of the JSONObject ---> https://newsapi.org/v2/everything?sources=fox-sports&apiKey=583d233722744e44954d03a1f4653c88

Please be aware that header called articles is a JSONArray.

https://newsapi.org/s/fox-sports-api

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!