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

iOS

Question about the Blog Reader code adaptation.

First off I love what you guys are doing here. What I have learned from here is far more valuable than any other resource I have available to me.

I have tried to adapt the BlogReader (iOS) to what I'm trying to do which is very very similar. But the code is getting lost.

What is the difference in the JSON output from your link and my link

I say this because once I have adapted my code and I run a NSLog(@"JSON Data:%@",dataDictionary); after the blogPostArray has been created I get the full response. And likewise, if I do a NSLog(@"BlogPostArray Contents:%@",blogPostsArray); I get the trimmed down code as I'm supposed to.

    2013-04-04 14:22:23.712 BlogReader[55958:c07] JSON Data:{
    count = 10;
    "count_total" = 1342;
    pages = 135;
    posts =     (
                {
            author = "Jake Rocheleau";
            date = "2013-04-04 09:30:45";
            id = 21581;
            thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/04/cmmntr-social-design-news-frontpage-150x150.png";
            title = "Most Helpful Webapps & Resources for Building Modern Websites";
            url = "http://blog.teamtreehouse.com/most-helpful-webapps-resources-for-building-modern-websites";
        },
                {
            author = "Josh Long";
            date = "2013-04-03 14:45:14";
            id = 21578;
            thumbnail = "<null>";
            title = "Move the Problem";
            url = "http://blog.teamtreehouse.com/move-the-problem";
        },
                {
            author = Treehouse;
            date = "2013-04-02 10:02:30";
            id = 21573;
            thumbnail = "<null>";
            title = "Web Typography, CSS Patterns and Simple Icons | Treehouse Show Ep 33";
            url = "http://blog.teamtreehouse.com/web-typography-css-patterns-and-simple-icons-treehouse-show-ep-33";
        },
                {
            author = "Matt West";
            date = "2013-04-01 13:30:28";
            id = 21559;
            thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/03/getusermedia-permissions-150x36.png";
            title = "Accessing the Device Camera with getUserMedia";
            url = "http://blog.teamtreehouse.com/accessing-the-device-camera-with-getusermedia";
        },
                {
            author = "Dan Gorgone";
            date = "2013-04-01 09:30:46";
            id = 21568;
            thumbnail = "<null>";
            title = "How to Make a Mixtape | Treehouse Quick Tip";
            url = "http://blog.teamtreehouse.com/how-to-make-a-mixtape-treehouse-quick-tip";
        },
                {
            author = "Scott Britton";
            date = "2013-03-29 16:10:10";
            id = 21567;
            thumbnail = "<null>";
            title = "Landing a Non-Technical Job at a Startup";
            url = "http://blog.teamtreehouse.com/landing-a-non-technical-job-at-a-startup";
        },
                {
            author = "Scott Magdalein";
            date = "2013-03-29 09:30:36";
            id = 21565;
            thumbnail = "<null>";
            title = "Get More Freelance Clients by Lowering Their Risk (and Yours)";
            url = "http://blog.teamtreehouse.com/get-more-freelance-clients-by-lowering-their-risk-and-yours";
        },
                {
            author = Treehouse;
            date = "2013-03-28 09:30:05";
            id = 21555;
            thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/03/html-validation-tutorial-treehouse-quick-tip-treehouse-blog-150x150.jpg";
            title = "HTML Validation Tutorial | Treehouse Quick Tip";
            url = "http://blog.teamtreehouse.com/html-validation-tutorial-treehouse-quick-tip";
        },
                {
            author = Treehouse;
            date = "2013-03-27 11:07:41";
            id = 21551;
            thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/03/how-to-choose-investments-and-change-the-world-excerpt-from-chamath-palihapitiya-treehouse-blog-150x150.jpg";
            title = "How to Choose Investments and Change the World with Chamath Palihapitiya";
            url = "http://blog.teamtreehouse.com/how-to-choose-investments-and-change-the-world-with-chamath-palihapitiya";
        },
                {
            author = "Jake Rocheleau";
            date = "2013-03-26 13:30:38";
            id = 21544;
            thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/03/featured-image-jquery-jcrop-cropping-photo-150x150.png";
            title = "Dynamic jQuery Image Avatar Cropping Effect";
            url = "http://blog.teamtreehouse.com/dynamic-jquery-image-avatar-cropping-effect";
        }
    );
    status = ok;
}

)

However, once I adapt my code as required for the different sources and variables at play here. Running the NSLog(@"JSON Data:%@",ministriesDictionary); at the same spot yields me the acceptable format of what I expect. Once I try to reduce the data down to just the "resources" (instead of "posts") due to the difference in backends I get (null) back as a response from my NSLog request of the newly created NSArray.

    2013-04-04 14:26:54.154 CSBC2[56141:c07] JSON Data:{
    entry =     {
        "@collection_url" = "http://api.storageroomapp.com/accounts/50ff0ad80f66027d84001680/collections/5150647e0f6602325600026e";
        "@created_at" = "2013-03-25T18:54:00Z";
        "@trash" = 0;
        "@type" = "Ministries_Collection";
        "@updated_at" = "2013-04-01T20:14:52Z";
        "@url" = "http://api.storageroomapp.com/accounts/50ff0ad80f66027d84001680/collections/5150647e0f6602325600026e/entries/51509d480f660208860008c6";
        "@version" = 4;
        "min_description" = "ABOUT 10:31 - STUDENT MINISTRY
    \nUnder the authority of the church and parents, we want to see teens living worthy of the gospel, through lives changed by the gospel. 10:31 is the middle and high school student ministry of Clear Springs Baptist Church. Through the cooperative efforts for family, friends, and the family of faith, we desire teens to experience, apply, and live worthy of the gospel of Christ for the glory of God.
\n
\nANNUAL EVENTS
\n 
\nREFUGE
\n
\n Refuge has traditionally been our most popular event all year. Every Spring students \U201cget away\U201d for a weekend of worship, games, food, and fellowship. Refuge is an opportunity for students to gather together and spend time in worship seeking to grow in their faith, finding that God alone is their refuge and strength. Refuge is founded upon the truth taught in Psalm 46:1, \"God is our refuge and strength, a very present help in trouble.\" We want every Spring to remind students to go to Christ,  for help and strenght; rather than turning to the world for answers and assurance.
\n 
\nWORTHY
\n
\nWorthy is our newest annual summer event for middle and high school students. During worthy students will be able to come together and serve Christ for the glory of the Savior.
\n 
\nNEXT LEVEL
\n
\nNext Level is our new annual Disciple Now weekend event in the fall to challenge students to move to the next level by learning what it means to be truly transformed by God\U2019s Word. We desire for students to heed the truth of God\U2019s Word taught in Hebrews 6:1, \U201cLet us leave the elementary teachings of Christ, and move on to maturity\U2026.\U201d During this weekend event both middle and high school students will stay in area homes for small group fellowship and meet together for corporate worship. Opportunities to perform local service projects will also be provided during the weekend. This is an annual event in which parents and students are encouraged to attend together, growing in their faith and moving on to maturity together\U2026in Christ. Time is spent addressing issues that directly relate both to students and parents alike. Don't miss out!!
\n
\n
\nCSBC STUDENT MINISTRY CORE VALUES
\n
\nWe are committed to producing a high view of the family among teenagers and their parents (Parent driven) Parent driven: \U201cUnder the authority of the church and parents\U2026\U201d
\n
\nParents, we as pastors want to assist you in training and making disciples of your teenagers. We believe that you are clearly commanded by Scripture to be the primary influences in the spiritual growth of your children. Ephesians 6:4 states that parents are to \U201cbring them up in the discipline and instruction of the Lord.\U201d Our goal as a youth ministry is to equip the parents of Clear Springs Baptist Church to do just that.
\n
\nSeeking to be a partner and a resource for parents in the task of parenting, seeking to involve families in the student ministry.
\n
\nWe are committed to producing a high view of the local church among teenagers. (Biblically-centered)
\n
\nTeaching driven: \U201c\U2026we want to see students living worthy of the gospel\U201d Our culture continually seeks to conform the thinking of our young people. Our teens are constantly being pulled by the enticements of the world. Youth will daily face many unique temptations for the first time as middle and high schooler\U2019s. In light of these temptations, we need to both preach Jesus Christ and help our young people understand how the gospel informs and directs every aspect of our lives. We seek to do this through our 10:31 meetings and retreats, often focusing on practical issues in the lives of teens and helping them to \U201clive worthy of the gospel.\U201d
\n
\nGiving students something that is significant not just shiny; called to engage not entertain. 
\n
\nReaching and winning students to Christ and teaching them to feed themselves.  The culture teaches our students that they must be entertained all the time (ipod, texting on their cells, etc. Today students have the most nibble thumbs in history. Look at culture and do the exact opposite.
\n
\nWe are committed to producing a high view of the gospel among teenagers in our church body that leads to growth in godliness and strong faith in Christ. Gospel driven: \U201c\U2026through lives changed by the gospel.\U201d
\n
\nThe teen years are unique years in the Christian walk. In the teen years, young people are faced with new temptations and feelings. Their own sinful nature finds a strong ally in the world, and therefore, these years are critical in helping young people avoid folly and instead, pursue life in Christ. Youth ministry is an evangelistic ministry because the teen years are a time when young people often intentionally choose to walk with the Lord. Therefore, the best thing we can do for our teens is to preach Christ. This statement recognizes that the starting place for true change is ONLY from a heart that has been changed by the gospel of Jesus Christ. It is from that genuinely converted heart that a teen can live worthy of the gospel. 
\n
\nSeeking to utilize the gifts and great potential God has placed within students for the good of the church and the advancement of the gospel around the world. 
\n
\nI look forward to partnering with you and your student,
\n
\nPastor Bill McCarter
\nPastor to Students";
        "min_external_description1" = "10:31 Student Website";
        "min_external_description2" = "10:30 Student Ministry Blog";
        "min_external_link1" = "http://www.csbc1031.com/";
        "min_external_link2" = "http://www.1031youth.blogspot.com/";
        "min_identity" = ministry1;
        "min_leader" = "Pastor Bill McCarter";
        "min_leader_contact" = "(865) 688-7674";
        "min_leader_email" = "email@email.com";
        "min_leader_photo" =         {
            "@processing" = 0;
            "@type" = Image;
            "@url" = "http://files.storageroomapp.com/accounts/50ff0ad80f66027d84001680/collection/5150647e0f6602325600026e/entries/51509d480f660208860008c6/fields/k5150647e0f66023256000275/file.jpg";
            "@versions" =             {
            };
        };
        "min_logo" =         {
            "@processing" = 0;
            "@type" = Image;
            "@url" = "http://files.storageroomapp.com/accounts/50ff0ad80f66027d84001680/collection/5150647e0f6602325600026e/entries/51509d480f660208860008c6/fields/k5150647e0f66023256000271/file.jpg";
            "@versions" =             {
            };
        };
        "min_meeting_times" = "10:31 is held every Wednesday Night for middle and high school students. This is an outreach event that includes skits, worship, and a speaker. High school and middle school students come together every week with other people their own age from 6:30 \U2013 7:30 pm. Invite your friends! 
\n
\n10:30 Hang Time is the 1st Wednesday of every month at 6:30 PM
\n
\nJOURNEY is what we call our time of weekly Family Bible study where students come together to connect with the Lord and each other. On Sunday mornings, classes are offered for 6th-12th grade at 9:15 a.m. on the second floor of the education building. Journey is designed to help students nourish friendships, learn from God's Word, and encourage one another in their daily walk with God. It's an awesome opportunity to come together every week with other people your age and develop your understanding of the one and only Jesus Christ. 
\n";
        "min_name" = "10:30 Student Ministry";
    };
    }
2013-04-04 14:26:54.161 CSBC2[56141:c07] BlogPostArray Contents:(null)

Any idea what is breaking here? I get no error what so ever, just no data.

Again, thanks for the service you guys are providing.

Zach

2 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

The structure of your JSON file is a bit different. In the Blog Reader the posts are at the root level:

  |- status
  |- count
  |- posts []

Whereas your JSON file is like this:

   |- array
       |- pages
       |- page
       |- resources []

That's why when you access resources from the dictionary it gives you back null because you first have to access the key array and then retrieve resources from it.

NSDictionary *arrayDictionary = [dataDictionary objectForKey:@"array"]; 
NSArray *resources = [arrayDictionary objectForKey:@"resources"];

Or you could write it one line:

    NSArray *resources = [[dataDictionary objectForKey:@"array"] objectForKey:@"resources"];

Amit you sir are the man! I could kiss you if you weren't a dude. I've been researching other backend options because I was getting so frustrated. You sir are a coding genius. :)

Can't wait for the next installment of the BlogApp.

Thanks again.

Zach