Xcode 4.3.2 ans SBJSON
问题描述:
我正在开发一个iOS
应用程序。我使用Xcode 4.3.2
和SBJSON
,我已经导入所有的JSON类我的项目,它编译罚款,但是当我在项目定位,我有这样的崩溃:-[__NSCFDictionary JSONRepresentation]: unrecognized selector sent to instance
Xcode 4.3.2 ans SBJSON
,并在我的代码我在做什么样这样的:NSString *jsonString = [dic JSONRepresentation];
DIC是NSDictionnary.
谢谢您的回答
答
尝试下面的代码,其中responseString是你从解析器收到您的回复字符串。
SBJSON *json = [SBJSON new];
NSMutableDictionary *jsonDictionary = (NSMutableDictionary*) [json objectWithString:responseString error:nil];
答
JSONRepresentation不是Apple的NSDictionary类的一部分。
这是JSON Api中包含的非常有用的类别。
=>您使用的是this JSON Api吗?
=>您是否正确导入了JSON Api头文件?
=>如果你有看的代码,被声明为JSONRepresentation类别:
@interface NSDictionary (NSDictionary_SBJsonWriting)
/// Returns a string containing the receiver encoded in JSON.
- (NSString *)JSONRepresentation;
@end
与.m文件对应的代码?
编辑:
如果你是一个静态库,并在其中(或其他API)使用JSON API时,你应该在你的库的构建设置和调用项目的人一些变化。
在您的库构建设置中,检查“其他链接器标志”行。该值应为:“-ObjC”
- 在调用项目的构建设置
,“其他连接标志”的值应该是“-all_load”
没有一个类SBJSON! – samir
它可用,你可以从https://github.com/dcgrigsby/luckynumbers/tree/master/Classes下载它。在JSON文件夹中有一些名为SBJSON.h&SBJSON.m的文件。 –
我已从这里下载项目https://github.com/stig/json-framework – samir