帮助解决 SBJSON + Facebook SDK 冲突

Posted

技术标签:

【中文标题】帮助解决 SBJSON + Facebook SDK 冲突【英文标题】:Help with SBJSON + Facebook SDK *** 【发布时间】:2011-09-01 02:57:37 【问题描述】:

我使用的是来自this JSON tutorial 的 SBJSON 文件,然后我尝试使用 Facebook ios SDK。 Facebook SDK 恰好有相同的 SBJSON 文件。但显然有很大不同。我不能同时使用这两个文件夹组,因为我在 Xcode 中遇到“重复错误”。我尝试删除原始 JSON 文件夹组,现在我收到以下警告:SBJsonParser may not respond to objectWithString:error:SIGABRT 在此行崩溃:return [jsonParser objectWithString:jsonString error:NULL];

有人知道我该如何解决这个问题吗?提前致谢!

// JSON from Server Actions
- (NSString *)stringWithUrl:(NSURL *)url 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
                                                cachePolicy:NSURLRequestReloadRevalidatingCacheData
                                            timeoutInterval:30];
    // Fetch the JSON response
    NSData *urlData;
    NSURLResponse *response;
    NSError *error;

    // Make synchronous request
    urlData = [NSURLConnection sendSynchronousRequest:urlRequest
                                    returningResponse:&response
                                                error:&error];

    // Construct a String around the Data from the response
    return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
    



- (id)objectWithUrl:(NSURL *)url 
    SBJsonParser *jsonParser = [SBJsonParser new];
    NSString *jsonString = [self stringWithUrl:url];

    // Parse the JSON into an Object
    return [jsonParser objectWithString:jsonString error:NULL];
    

- (NSDictionary *)downloadManifest 
    id response = [self objectWithUrl:[NSURL URLWithString:@"http://example.com/manifest.json"]];
    NSDictionary *feed = (NSDictionary *)response;
    return feed;
    

【问题讨论】:

【参考方案1】:

https://nodeload.github.com/gabriel/yajl-objc/zipball/master

试试这个解析器...

【讨论】:

您是否因为没有解决方案而最终使用了新的 JSON 解析器?恕我直言,切换 JSON 库似乎不是一个很好的解决方案。

以上是关于帮助解决 SBJSON + Facebook SDK 冲突的主要内容,如果未能解决你的问题,请参考以下文章

如何解决 Facebook ID 错误

Facebook ios-sdk:提要帖子不显示在新闻提要上

不要使用SBJSON(json-framework)

不要使用SBJSON(json-framework)

使用 SBJSON 解析和检查 JSON

SBJSON 解析器内存泄漏