2014-06-15 145 views
0

快速的问题:解析的NSString与SBJSON

如何使用SBJSON4 的字符串是UTF-8从Web REST API编码的JSON字符串我解析的NSString。 我需要一个带解析数据的NSDIctionary。该字符串保证是一个完整的JSON文档。

@interface NSOperationParseJSON() 

@property (weak, nonatomic) id<JSONParseDelegate> delegate; 
@property (strong, nonatomic) NSString *stringToParse; 
@property (strong, nonatomic) SBJson4Parser *jsonParser; 

@end 

@implementation NSOperationParseJSON 

- (instancetype)initWithJSONString:(NSString *)jsonString andDelegate:(id<JSONParseDelegate>)delegate 
{ 
    self = [super init]; 
    if (self) { 
     _delegate = delegate; 
     _stringToParse = jsonString; 
     _jsonParser = [[SBJson4Parser alloc] init]; 
    } 
    return self; 
} 

#pragma mark - OVERRIDEN 

- (void)main 
{ 
    @autoreleasepool { 
     if (self.isCancelled) { 
      return; 
     } 

     SBJson4ParserStatus responseCode = [self.jsonParser parse:[self.stringToParse dataUsingEncoding:NSUTF8StringEncoding]]; 

     if (responseCode == SBJson4ParserComplete) { 

     } else if (SBJson4ParserError) { 

     } 

    } 
} 

我从哪里得到答复?

+0

你为什么不使用NSJSON? –

+0

非标准json。我有一些键是像“@数据”...和NSJSON无法处理这些类型的JSON。 – user1028028

回答