1

我正在尝试以这种方式制作一个 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)' ***

我的问题是什么,我怎样才能让它发挥作用?

4

0 回答 0