【发布时间】:2014-08-05 08:41:45
【问题描述】:
快速提问:
如何使用 SBJSON4 解析 NSString 该字符串是来自 Web REST api 的 UTF-8 编码 JSON 字符串。 我需要一个带有解析数据的 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) {
}
}
}
我从哪里得到响应?
【问题讨论】:
-
你为什么不使用 NSJSON ?
-
非标准 json。我有一些类似“@data”的键......而 NSJSON 无法处理这些类型的 json。
标签: ios objective-c sbjson