- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 iOS 开发新手。我有一个用字典填充的 NSMutableArray
。我需要将 NSMutableArray
保存在 NSUserDefaults
中。这是我传递给我的 NSMutableArray
的数据:
{
"sub_slots" ={
address = "501 Balestier Road #02-01 Wai Wing Centre";
"avail_id" = 2230;
"branch_id" = 600;
"branch_name" = Balestier;
"company_description" = "At Action X, we design, produce and deliver highly interactive sports events around the world. Through innovation, we revolutionize the sports entertainment landscape with the simple goal of creating happiness for people.";
"company_id" = 222;
"company_name" = "Action X";
"d_salary_from" = 7;
"d_salary_to" = 7;
date = "<null>";
description = "Interview: Face to face interview period from 4th - 8th May (in office)
Working hours: 7am - 10am and 11am - 2pm (1 hour lunch break from 10am to 11am)
Minimum 5 working days (excluding PH)
Generating sponsorship leads in Australia.
Payment method: Cheque";
direction = "From Toa Payoh MRT Station (NS19).
Walk 109 m to Toa Payoh Interchange.
Board Bus 139, 145 at Toa Payoh Interchange, alight at Opposite Moulmein Community Center, Balestier Road, 3 stops later.
Walk 34 m to Wai Wing Centre.";
"end_date_time" = "";
"expired_at" = "2015-05-08T19:21:01.000+08:00";
followed = 0;
grade = 2;
"incentives_and_benefits" = "{\"food\":{\"0\":\"\"},\"commission\":{\"1\":\"$2 for first 9 appointments, $5 for all appointments if minimum 10 appointments hit.\"},\"uniform\":{\"0\":\"\"},\"transport\":{\"0\":\"\"},\"extras\":{\"0\":\"\"}}";
"is_anytime" = 1;
"is_permanent" = 1;
"is_quick_job" = 0;
"job_function_name" = Telemarketer;
latitude = "1.326446";
location = "1.326446,103.84705";
longitude = "103.84705";
"main_slot_id" = 2230;
"mandatory_requirements" = (
"Good communication skills in English",
"Well groomed, pleasant and positive work attitude",
"Need to commit for 1 month"
);
"offered_salary" = 7;
"optional_requirements" = (
);
"postal_code" = 329844;
priority = 1;
"publish_salary" = 1;
published = 1;
"start_date_time" = "";
status = MA;
"sub_slot_id" = 2230;
"ts_end_date_time" = 0;
"ts_expired_at" = 1431084061;
"ts_start_date_time" = 0;
zone = central;
};
},
}
我尝试使用以下方法保存它:
[[NSUserDefaults standardUserDefaults] setObject:myMutableArray forKey:@"locations"];
[[NSUserDefaults standardUserDefaults] synchronize];
当我尝试运行应用程序时,它在这段代码中崩溃。这是我收到的错误:
2015-05-08 18:19:29.559 Matchimi[477:82076] Property list invalid for format: 200 (property lists cannot contain objects of type 'CFNull')
2015-05-08 18:19:29.654 Matchimi[477:82076] Attempt to set a non-property-list object ( ) for key locations.
任何帮助将不胜感激。谢谢。
最佳答案
发生的事情是"<null>"
表示您尝试存储的值之一是 NSNull
类型.此类型不能存储在 NSUserDefaults
中,因此您需要删除值为 NSNull
的所有键/值对存储之前:
NSMutableArray *keysToRemove = [NSMutableArray new];
NSArray *keys = [dict allKeys];
for (NSString *key in keys) {
id value = dict[key];
if ([value isKindOfClass:[NSNull class]])
[keysToRemove addObject:key];
}
for (NSString *key in keysToRemove]
[dict removeObjectForKey:key];
(假设 dict
是一个 NSMutableDictionary
)。
当您从 NSUserDefaults
读回数据时为丢失的键/值对做好准备,如果您找到任何键/值对,您可以假设它们的值为空。
关于ios - 如何在 NSUserdefaults 中保存 NSMutablearray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30122933/
在 viewDidLoad 上,我的应用程序填充 NSMutableArray arrayOfHaiku,它是 NSDictionary 项的数组,如下所示: NSError *error; NS
我在 NSMutableArray 上是这样的: NSMutableArray *array = [NSMutableArray arrayWithObjects:@"0",@"0",@"0",@"0
我正在尝试设置我的 allArticlesArray 的内容,然后将附加对象附加到数组中。这是我的代码片段: [self.allArticlesArray setArray:newsArray]; [
我用 NSMutableArray 中的数据填充了 TableView ,一切正常。当我选择一个单元格(didSelectRowAtIndex)时,该项目将从数组中删除,正如它应该做的那样。现在我希望
我有一个 NSMutableArray 是我的代表,我也在我的一个 View Controller 中使用它。 所以在 viewDidLoad 我像这样制作我的 NSMutableArray 的可变副
我有 100 个元素的 NSMutableArray。 我想将“20 - 50”、“10 - 20”、“60 - 100”和 50 - 60. 元素加载到单独的 NSMutableArray 中,并将
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
我在尝试将字符串的 NSMutableArray 共享给另一个类时遇到了一些问题。我有一个 tableView,其中填充了 Strings,我想将其添加到 NSMutableArray。然后在另一个
正如我们所知,数组是一个连续的内存分配。那么 NSMutableArray 大小将如何增加。 最佳答案 C 数组确实使用连续内存,C++ std::vector 也是如此,但是 NSMutableAr
我需要对一个数组进行排序,里面有一个数组,像这样: NSMutableArray * array_example = [[NSMutableArray alloc] init]; [array_e
这看起来很简单,但我只是得到一个空数组。 我想获取一个按下的按钮,找到它旁边的所有按钮(参见代码中的注释),并将所有找到的按钮添加到另一个 NSMutableArray。 然后我想遍历该数组并对每个按
我正在尝试在另一个 NSMutableArray 中添加 NSMutableArray。但我想做的是嵌套数组。 我当前的代码是: NSMutableArray *array1 = [NSMutab
我有三个类,即DepartmentViewController、DepartmentRequest、Department。这就像我从 DepartmentViewcontroller 发出部门请求,并
我正在尝试将 NSMutableArray 存储在 NSMutableArray 中。所以 var all:NSMutableArray = NSMutableArray() let localArr
这一定是那些错误之一,您一直盯着代码看很长时间,以至于找不到错误。 我有这个代码块,我在其中循环遍历一个包含多个 NSMutableArray 的 NSMutableArray: // FoodVi
我有一个包含 50 个条目的 NSMutableArray - 有什么简单的方法可以将其分成 5 个 NSMutableArray,每个 10 个条目。 最佳答案 是的,要划分 NSMutableAr
我想将 NSMutableArray 的 addObject 放入 NSMutableArray 中,那么我如何快速实现这一点。并检索它,所以请帮助我,因为现在我正在快速学习。 间接说我要二维数组是指
好吧: 我有 NSMutableArray 1 我还有 NSMutableArray 2 我想从数组 1 中删除与数组 2 中的对象匹配的所有对象。 有什么想法吗? 最佳答案 我刚刚打开文档,打印 N
我正在尝试制作 NSMutableArray 的深拷贝,其对象是与此类似的自定义类的实例: @interface CustomParent : NSObject @property NSInteger
我知道你们可能会觉得这是一个重复的问题。但我对我的项目的这个问题搞砸了。 现在转到这个问题,我已经采取了NSMutableArray命名为 arr1包含字符串值,例如 @"34" , @"40"等等。
我是一名优秀的程序员,十分优秀!