I have a json http://gdata.youtube.com/feeds/api/users/ruflixnet/playlists?v=2&alt=jsonc and i want to get id,title and size, but don't now how to do that.
Asked
Active
Viewed 3,465 times
0
-
There are sevral libraries for that depending on which language you are coding in at http://json.org/. http://blog.zachwaugh.com/post/309924609/how-to-use-json-in-cocoaobjective-c is one example. – MrKiane Jun 04 '12 at 08:33
-
DON'T WORK !!! see antonio answer – Sp0_od Jun 04 '12 at 09:34
-
i have posted the almost all code and the way to do see my code below – james Jun 04 '12 at 11:54
4 Answers
1
Use the SBJSON libraries for example, IVe been using them all time and they are pretty good.
You have a tutorial here:
http://blog.zachwaugh.com/post/309924609/how-to-use-json-in-cocoaobjective-c

Antonio MG
- 20,382
- 3
- 43
- 62
1
download the JSON library and include that in your project than make this following class for your data Make NSObject class
ObjectData.h
@interface ObjectData : NSObject {
NSString *id;
NSString *title;
NSString *size;
}
@property(nonatomic,retain) NSString *id;
@property(nonatomic,retain) NSString *title;
@property(nonatomic,retain) NSString *size;
@end
ObjectData.M
#import ObjectData.h
@implementation ObjectData
@synthesize id;
@synthesize title;
@synthesize size;
@end
Make another DataController Class
#import <Foundation/Foundation.h>
@interface DataController : NSObject {
}
+ (id)staticVersion;
- (NSMutableArray *) startParsing:(NSString *)theURLString;
end
#import "DataController.h"
@implementation DataController
DataController *theInstance;
+(id)staticVersion
{
if(!theInstance){
theInstance = [[DataController alloc] init];
}
return theInstance;
}
- (NSMutableArray *) startParsing:(NSString *)theURLString {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",theURLString]];
NSString *fileContent= [NSString stringWithContentsOfURL:url];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:fileContent error:nil];
NSArray *items = (NSArray *) data ;
return items;
}
@end
And in View Did load
NSArray *tempArray =[[DataController staticVersion] startParsing:serverName];
for (int i = 0; i<[tempArray count]; i++) {
id *item = [tempArray objectAtIndex:i];
NSDictionary *dict = (NSDictionary *) item;
ObjectData *theObject =[[ObjectData alloc] init];
[theObject setid:[dict objectForKey:@"id"]];
[theObject settitle:[dict objectForKey:@"title"]];
[theObject setsize:[dict objectForKey:@"size"]];
[resultArray addObject:theObject];
[theObject release];
theObject=nil;
At last make preferenc.h file and give the your json data path
#import <Foundation/Foundation.h>
#define serverName @"http://gdata.youtube.com/feeds/api/users/ruflixnet/playlists?v=2&alt=jsonc"
hope this works fine

james
- 646
- 3
- 9
- 24
0
use SBJson
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSMutableDictionary *dicRes = [parser objectWithString:stringFromServer error:nil];

gauravds
- 2,931
- 2
- 28
- 45