首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用SBJSON解析NSString

用SBJSON解析NSString
EN

Stack Overflow用户
提问于 2014-06-15 17:17:35
回答 1查看 1.2K关注 0票数 0

快速问题:

如何使用SBJSON4解析NSString该字符串是来自web REST api的UTF8编码的JSON字符串。我需要一个包含解析数据的NSDIctionary。该字符串被保证是一个完整的JSON文档。

代码语言:javascript
复制
   @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) {

        }

    }
}

我从哪里得到回应?

EN

回答 1

Stack Overflow用户

发布于 2014-06-22 22:32:44

您需要仔细阅读文档。版本4的界面与之前的版本有很大的不同。尽管它支持NSJSONSerialisation不支持的一些工作模式,比如处理不完整的JSON流,但它不支持非标准的JSON (除非我漏掉了一个bug )。

如果你还想探索它,这里有两个例子:

https://github.com/stig/ChunkedDeliveryhttps://github.com/stig/DisplayPretty

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24228176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档