This thread was quite helpful for getting started, but I'm currently struggling to pull the data from a JSON feed of the following format:
Code:
{
"group": {"slug": "recent-activity", "entries": [
{
"unique_id": "http://delicious.com/url/b91962bd93dbb86863323b410e9a1a60#cmeinke",
"title": "The Nature of Code. Chapter 1: Vectors",
"raw_content": "Draft chapter one of upcoming book "The Nature of Code" by Daniel Shiffman",
"url": "http://www.scribd.com/doc/15888334/The-Nature-of-Code-Chapter-1-Vectors",
"raw_title": "The Nature of Code. Chapter 1: Vectors",
"feed_id": 693,
"content": "Draft chapter one of upcoming book "The Nature of Code" by Daniel Shiffman",
"published_at": "2009-06-03T10:59:38Z"
}, ...
source: http://feedstitch.com/cmeinke/recent-activity.json
Code:
public class JsonTest01 extends PApplet{
public void setup(){
try {
JSONObject activityData = new JSONObject(join(loadStrings("recent-activity.json"), ""));
JSONArray entries = activityData.getJSONArray("entries");
for (int i = 0; i < entries.length(); i++) {
JSONObject entry = entries.getJSONObject(i);
println("Entry content:" + entry.getInt("feed_id") + " : " + entry.getString("title"));
}
}
catch (JSONException e) {
println (e.toString());
}
}
}
I'm currently trying to fetch the data with getJSONArray() but getting the following error:
Quote:org.json.JSONException: JSONObject["entries"] not found.
I broke down the structure of the JSON feed provided by FeedStitch and realized that if I strip it down to the "entries" array everything is working as expected.
Code:
// original structure
{
"group": {
"slug": "YourFeedSlug",
"entries": [
{
"unique_id": "",
"title": "", "raw_content": "",
"url": "",
"raw_title": "",
"feed_id": int,
"content": "",
"published_at": ""
}, ...
],
"title": "YourFeedTitle", "description": null
}
}
// stripped down to "entries" array
{
"entries": [
{
"unique_id": "",
"title": "", "raw_content": "",
...
},
],
Now I'm looking for a way to get around the group and meta information (slug, title, ...) to keep things dynamic. Any ideas or suggestions
Edit:Finally got the object stucture of JSON. Jer's post:
Processing, JSON & The New York Times helped understanding how to fetch objects located within other objects.
Sorry fro spamming this thread. :|