ios – NSJSONSerialization崩溃的应用程序

前端之家收集整理的这篇文章主要介绍了ios – NSJSONSerialization崩溃的应用程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一本字典,当我记录它时显示
{
    Date = "2013-04-30 17:17:18 +0000";
    Description = Kb;
    EventID = "92193e58-c04a-4233-9a6c-1332bc056b20";
    Title = Keyboard;
}

我正试图将它变成NSData,用于像这样的JSON Web服务……

- (NSData *)JSONRepresentation
{
    NSDictionary *dictionary = [self dictionaryObject];

    NSError *jsonError;

    NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dictionary
                                                       options:0
                                                         error:&jsonError];  //This is where the error occurs.

    return JSONData;
}

但每次我运行它时,应用程序都会崩溃.

字典正确形成,应用程序只是崩溃在这一行.

在AppCode中,我收到崩溃报告……

EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT,subcode=0xdefe))

在Xcode中,应用程序停止,如果我尝试继续,它会因错误而停止…

EXC_BAD_ACCESS (code=1,address=0x0)

解决方法

您的密钥是转换为JSON的无效对象. From the docs

An object that may be converted to JSON must have the following
properties:

The top level object is an NSArray or NSDictionary. All objects are instances of NSString,NSNumber,NSArray,NSDictionary,or NSNull. All dictionary keys are instances of NSString. Numbers are not NaN or infinity.

原文链接:https://www.f2er.com/iOS/332335.html

猜你在找的iOS相关文章