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
in newsfeedviewcontroller.m
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?
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;
}
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?
Last edited by a moderator: