json parsing to uitableview

Discussion in 'iPhone/iPad Programming' started by ashurmx, Feb 15, 2012.

  1. ashurmx, Feb 15, 2012
    Last edited by a moderator: Feb 15, 2012

    macrumors newbie

    Joined:
    Feb 15, 2012
    #1
    hi ,i am using RESTkit webservices,and i have to create newsfeed. so i have to get json parsing and i am stuck somewhere.

    restapi.m
    Code:
    -(void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {  
    
     else if ([request isGET]) {
    
            NSLog(@"GET response: %@", [response bodyAsString]);
    
            
    
            if ([request.resourcePath isEqualToString:[TeamieRestAPI resourceURL:TeamieUserNewsfeedRequest]]) { // if it's a request to get User Newsfeed
    
                if ([response isOK]) {
    
                    NSDictionary * newsfeed = [[response bodyAsString] objectFromJSONString];
    
                    
    
                    [self.delegate requestSuccessful:TeamieUserNewsfeedRequest withResponse:newsfeed];
    
                }
    
                else {
    
                    [self.delegate requestFailed:[NSString stringWithFormat:@"%i", response.statusCode] forRequest:TeamieUserNewsfeedRequest];
    
                }
    
            }
    
       -(BOOL)teamieUserNewsfeed:(NSDictionary*)params{
    
        NSString * newsfeedURL = [TeamieRestAPI resourceURL:TeamieUserNewsfeedRequest];    
    
        [[RKClient sharedClient] get:newsfeedURL queryParams:params delegate:self];
    
    #ifdef DEBUG
    
        NSLog(@"Newsfeed request sent...");
    
    #endif
    
        return YES;
    
    }
    
    in newsfeedviewcontroller.m
    Code:
    // the function that is called once the Newsfeed is loaded
    
    // Also contains code to parse throught the JSON structure
    
    -(void)userNewsfeedDidLoad:(NSDictionary *)response {
    
        
    
        NSDictionary * newsfeed = [response valueForKey:@"thoughts"];
    
        
    
        // print the 'title' and 'method' of all filters
    
        for (id item in [newsfeed valueForKey:@"filters"]) {
    
            
    
            NSLog(@"Filter Title: %@ with method: %@", [item valueForKey:@"title"], [item valueForKey:@"method"]);
    
        }
    
        
    
        // print 'html' of each thought along with 'timestamp' and 'real_name' of the user who posted the thought
    
       
    
        for (id thoughtid in [newsfeed valueForKey:@"thought"]) {
    
           
    
            NSDictionary * thought = [[newsfeed valueForKey:@"thought"] valueForKey:thoughtid];
    
         
    
            NSLog(@"Message '%@' %@ by %@", [[thought valueForKey:@"message"] valueForKey:@"html"], [[[thought valueForKey:@"timestamp"] valueForKey:@"time"] valueForKey:@"text"], [[thought valueForKey:@"user"] valueForKey:@"real_name"]);
    
    }
    
    }
    
    
    i want to show on uitable view -- html as message ,, text as time ,, real_name as name

    i am getting some problem parsing these elements and shwing on tableview..

    can you help in this?
     
  2. macrumors 6502

    Joined:
    Jan 21, 2008
    Location:
    Texas
    #2
    One step at a time. Are you able to parse your values out of the JSON and print them to the log? Are you getting the correct raw response from the sever?
     

Share This Page