1

我是第一次使用 SBJson 框架,我遇到了一个大问题,下面的代码总是返回 null。NSDictionary 已正确填充(我打印了每个值!)。

NSDictionary *nsDictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys];
SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];
NSString *jsonString = [jsonWriter stringWithObject:nsDictionary];
NSLog(@"%@", jsonString);  

我也试过这个:

NSDictionary *nsDictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys];
SBJsonWriter *jsonWriter = [SBJsonWriter new];
NSString *jsonString = [jsonWriter stringWithObject:nsDictionary];
NSLog(@"%@", jsonString);  
4

1 回答 1

2

字典可能包含无法写入的对象SBJsonWriter

您可以使用-[SBJsonWriter stringWithObject:error:]来获取失败的原因。

NSDictionary *nsDictionary = [NSDictionary dictionaryWithObjects:values forKeys:keys];
SBJsonWriter *jsonWriter = [SBJsonWriter 新];
NSError *error = nil;
NSString *jsonString = [jsonWriter stringWithObject:nsDictionary 错误:&error];
如果(!jsonString){
    NSLog(@"错误:%@", 错误);
}
于 2012-07-09T10:09:52.430 回答