gpt4 book ai didi

ios - NSJSONSerialization 崩溃的应用程序

转载 作者:可可西里 更新时间:2023-11-01 03:27:47 26 4
gpt4 key购买 nike

我有一本字典,当我登录时它会显示...

{
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.

关于ios - NSJSONSerialization 崩溃的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16305584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com