从NSDictionary生成JSON字符串会引发异常

时间:2012-11-08 12:19:53

标签: objective-c json macos

我正试图以这种方式制作一个json字符串:

NSData* jsonData = [NSJSONSerialization dataWithJSONObject:JSONDictionary options:NSJSONWritingPrettyPrinted error:&error];
NSString* json = nil;
if (! jsonData) {
    NSLog(@"Got an error: %@", error);
} else {
    json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

其中JSONDictionary初始化为:

NSDictionary *JSONDictionary = [NSDictionary dictionaryWithObjectsAndKeys: dateString, @"start",  [self.currentlyConnectedPeripheral UUID], @"device_id", [self.currentlyConnectedPeripheral name], @"device_name", rrs, @"rates", @"123", @"id", nil];

但我的申请引发了一个例外:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSCFType)' ***

我的问题是什么,如何让它发挥作用?

0 个答案:

没有答案