Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不推荐使用SBJson iOS解析器方法?_Ios_Json_Sbjson - Fatal编程技术网

不推荐使用SBJson iOS解析器方法?

不推荐使用SBJson iOS解析器方法?,ios,json,sbjson,Ios,Json,Sbjson,我正在用SBJson解析器启动一个新项目,人们似乎推荐它为新的iOS项目提供互联网上最好的解析器。我有一个非常严重的问题,即Stig Brautaset声称您可以在上使用的当前方法似乎已被弃用,或者至少我的编译器是这么说的。我似乎两个都不能工作: NSDictionary *dict = [responseString JSONValue]; 这似乎是最新的方法,或者: NSDictionary *dict = [parser objectWithString:responseString e

我正在用SBJson解析器启动一个新项目,人们似乎推荐它为新的iOS项目提供互联网上最好的解析器。我有一个非常严重的问题,即Stig Brautaset声称您可以在上使用的当前方法似乎已被弃用,或者至少我的编译器是这么说的。我似乎两个都不能工作:

NSDictionary *dict = [responseString JSONValue];
这似乎是最新的方法,或者:

NSDictionary *dict = [parser objectWithString:responseString error:&error];
其中parser是一个sbjson解析器。XCode突出显示了这两个函数,并告诉我它们已被弃用


我在这里做错了什么???

看看源代码,看起来两者都有

- (id)objectWithString:(NSString*)jsonText error:(NSError**)error

从版本3.2起已弃用,将在版本4.0中删除。 您确定正在使用3.1吗

另一方面,两者

- (id)objectWithString:(NSString *)repr;

看起来可用,而不是弃用

我建议你改用它们


另一种方法是使用Apple提供的类。

这只是一种使用xcode it self轻松解决问题的通用方法。 每当任何一行代码被弃用时,最好按住键盘上的“alt”键,移动到引起问题的对象上,然后单击。 然后,Xcode建议编写代码的更好方法。 希望这有帮助

尝试替换:

NSDictionary *dict = [responseString JSONValue];
与:

或者更好:

SBJsonParser *parser = [SBJsonParser new];
id object = [parser objectWithString:responseString];
if (parser.error || ![object isKindOfClass:[NSDictionary self]])
    @throw parser.error ?: @"not a json dictionary";// or any error handling alternative
NSDictionary *dict = object;

为什么不使用apple的NSJSONSerialization类?是最好的解析器。如果您不想在iOS 5.0及更高版本中使用外部代码和目标设备,NSJSONSerialization是可以的。如果您不关心iOS4.x及以下版本(谁关心,对于新项目?),我建议NSJSONSerialization,除非您特别需要流式处理支持。然而,SBJson的当前版本实际上是3.2,您提到的方法的弃用也是如此。我不确定SBJson的用途,但我肯定有最新版本。文档有点粗略,你有一个更新的版本,显然是3.2。但是,它缺少文档,这就是为什么您没有看到弃用警告的原因。到底缺少什么文档?(我这样问只是为了改进它。)参见此处的警告::Stig,是的,您确实记录了它,但与其只是描述某件东西不推荐使用,不如描述可以在其位置使用的东西。只是一个想法。不适用于SBJson反对:没有建议。
NSDictionary *dict = [responseString JSONValue];
NSDictionary *dict = [[SBJsonParser new] objectWithString:responseString];
SBJsonParser *parser = [SBJsonParser new];
id object = [parser objectWithString:responseString];
if (parser.error || ![object isKindOfClass:[NSDictionary self]])
    @throw parser.error ?: @"not a json dictionary";// or any error handling alternative
NSDictionary *dict = object;