转换NSJSONSerialization到iOS 4(Converting NSJSONSeria

2019-09-30 05:10发布

我将支持IOS 5到iOS 4的项目,并有一定的困难。 它使用类AFNetworking ,我的问题是在下面一行:

iOS 5中:(伟大工程)

self.responseJSON =[NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error];

由于NSJSONSerialization没有在iOS 4的支持,我用这个:

self.responseJSON = AFJSONDecode(self.responseData, &error);

是什么让我的错误:

Undefined symbols for architecture i386:
  "_AFJSONDecode", referenced from:
      -[AFJSONRequestOperation responseJSON] in AFJSONRequestOperation.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Answer 1:

在该AFNetworking页的要求部分规定:

对于与iOS 4.3的兼容性,使用最新版本0.10.x。

在掠代码为0.10.1版本 ,我看到文件AFJSONUtilities.m ,这似乎处理JSON解码。 因为它需要的iOS 5或以上,其具有NSJSONSerialization这是不存在于AFNetowrking的最新版本。

你可能会想尝试版本0.10.1,如果你还没有准备好,而不是修改当前版本在iOS 4工作,因为你可以对付JSON问题后遇到额外的障碍。



Answer 2:

最好的办法是使用JSON处理第三方库在iOS 4和更早版本。 我会建议JSONKit。 https://github.com/johnezang/JSONKit



文章来源: Converting NSJSONSerialization to ios 4