Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Michael Zanfardino
Michael Zanfardino
2,416 Points

Converting Blog Post to JSON?

Was wondering how you convert your blog post in Wordpress to a JSON string. In the video "Build a Blog Reader iPhone App" badge 3 "Getting Data from the Web" author Amit Bijlani demos parsing the teamtreehouse blog API JSON string. My question is...how do I convert my blog post in Wordpress to a JSON string like the URL shared by Amit Bijlani in video 3 of this badge (URL below).

http://blog.teamtreehouse.com/api/get_recent_summary/

Thanks in advance!

mz

8 Answers

Haven't tried, but something like this should work: http://wordpress.org/extend/plugins/json-api/

Michael Zanfardino
Michael Zanfardino
2,416 Points

Thank you!!! I appreciate the quick response and help! Also, Amit, love the videos.

mz

Michael Zanfardino
Michael Zanfardino
2,416 Points

How would this work with a networked wordpress setup. We have the admin user, but also multiple users. I installed the JSON plugin and updated the core.php with the additional function. When I go the URL http://blog.mywebsite.com/api/get_recent_summary/ it works and generates the JSON of my recent post. But, if I go to a users page like so...http://blog.mywebsite.com/user/api/get_recent_summary/. I get the "can't find what you are looking for" error message (404).

Thanks in advance! mz

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

You would have to modify the core.php and create a new function to get blog post by user and pass it the user id. Check out the other functions in core.php as an example.

Amit, I don't think I can install the JSON API plugin because I have a .com site rather than a .org site http://en.support.wordpress.com/com-vs-org/.

What other options are there for extracting my blog data?

Eliezer Marte
Eliezer Marte
4,728 Points

Where exactly do you put the function with in the json-api/controllers/core.php Amit Bijlani?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Anywhere inside the core.php file should work.

Eliezer Marte
Eliezer Marte
4,728 Points

Also I'm having trouble making the app work in airplane mode. If it's not connected to wi-fi it'll crash upon opening. Seems like something is wrong with the NSDictionary