将NSJSONSerialization转换为ios 4
我正在将一个支持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)
AFNetworking页面的Requirements部分指出:
为了与iOS 4.3兼容,请使用最新的0.10.x版本。
看着版本0.10.1的代码 ,我看到文件AFJSONUtilities.m ,似乎处理JSON解码。 这在最新版本的AFNetowrking中不存在,因为它需要具有NSJSONSerialization的iOS 5或更高版本。
如果您尚未尝试版本0.10.1,而不是修改当前版本以在iOS 4上运行,因为在处理JSON问题之后可能会遇到其他障碍。
最好的办法是在iOS 4及更早版本上使用第三方库进行JSON处理。 我会推荐JSONKit。 https://github.com/johnezang/JSONKit