Arranging data obtained from REST API calls

Hi, 

For a few days now i’ve been learning about the corona sdk network request and obtaining data from http requests and I just wanted to know how I can take the json data obtained and arrange it in a lists.

For example - 

this is my request 

https://news.com/v1/articles?source=techcrunch&sortBy=top&apiKey=77eaa5eea3514cc18e04d8fcc712d8a2

and this is the json response–

{ "status": "ok", "source": "techcrunch", "sortBy": "top", "articles": [{ "author": "Catherine Shu", "description": "Samsung Electronics announced today that it has agreed to acquire cloud-computing company Joyent. In a statement, the Korean tech giant said that the..", "title": "Samsung will acquire cloud-computing company Joyent", "url": "http://social.techcrunch.com/2016/06/15/samsung-joyent/", "urlToImage": "https://tctechcrunch2011.files.wordpress.com/2016/06/shutterstock\_175600700.jpg?w=764&h=400&crop=1", "publishedAt": "2016-06-15T21:29:10" }, ...] }

Now to questions -

  1. How do i refer to a specific index of json data obtained?

  2. I would receive a many numbers of similar block of json data as shown above from one call , can you give an example on using for loop how can i arrange the similar datas in a newsfeed like UI?

Thanks

Kallol

local data = json.decode(event.response)
local news = data.articles
for i=1, #news do
print("this is article "…i)
print(news[i].title)
end

I’m having trouble accessing that URL to see the full feed. But it looks like a JSONfied RSS feed. We have a sample app on our github repo that handles XML based RSS feeds and while that part won’t do you much good, it does demonstrate on how to add the data to tableViews for display and such.

https://github.com/coronalabs-samples/business-app-sample

I see as I was typing this Scott also hit the second part of this. JSON data needs to be converted to a Lua table before you do that. We have an API call in the json.* API’s that will decode a block of JSON data and turn it into a Lua table indexed by key-values for things that are individual entities and as a numeric array when you have multiple of the same items. I’m assuming Scott got to the actual feed because his code looks right.

local data = json.decode(event.response)
local news = data.articles
for i=1, #news do
print("this is article "…i)
print(news[i].title)
end

I’m having trouble accessing that URL to see the full feed. But it looks like a JSONfied RSS feed. We have a sample app on our github repo that handles XML based RSS feeds and while that part won’t do you much good, it does demonstrate on how to add the data to tableViews for display and such.

https://github.com/coronalabs-samples/business-app-sample

I see as I was typing this Scott also hit the second part of this. JSON data needs to be converted to a Lua table before you do that. We have an API call in the json.* API’s that will decode a block of JSON data and turn it into a Lua table indexed by key-values for things that are individual entities and as a numeric array when you have multiple of the same items. I’m assuming Scott got to the actual feed because his code looks right.