Tag: nsdictionary

将数据保存在NSDictionary从NSDictionary

这里是我的JSON格式的数据,我已经parsing并保存在一个名为NSDictionary * dic的词典中。我有一个名为dic1的NSDicitonary,我只想将数据从// 1存储到// 3,我该怎么做?请帮帮我 ? //0 [{ "about": "Mother, actor, entrepreneur, fitness enthusiast and an eternal positive thinker", "id": "238bb4ca-606d-4817-afad-78bee2898264", "username": "Shilpa shetty kundr" } //1 , { "about": "Www.Nargisfakhri.com Instagram- @NargisFakhri Twitter- @NargisFakhri FaceBook- Nargis Fakhri ", "id": "cda99c24-955a-4c58-a6a8-c811938df530", "username": "Nargis Fakhri" } //2 , { "description": "Celebrating Black Friday in this lovely […]

如何更新ios中的plist文件

我正在开发一个应用程序。在这我试图更新plist文件使用下面的代码。 plist_path=[[NSBundle mainBundle]pathForResource:@"Configurationfile" ofType:@"plist"]; config_dict=[[NSMutableDictionary alloc]initWithContentsOfFile:plist_path]; [config_dict setValue:textField.text forKey:@"ServerURL"]; NSLog(@"%@",config_dict); [config_dict writeToFile:plist_path atomically:YES]; [config_dict release]; 但它不工作,但NSlog显示字典中的每个键的正确值。请帮助我如何更新plist文件。

以JSON格式的string文件,如何将filecontent读入NSDictionary

我的应用程序包中只有一个文件“xyz.txt”,只有JSON格式的文本。 我想打开文本文件的文件path,并将内容读取到NSDictionary。 怎么做。 我已经准备好了我的JSONstring。 只需要启动到NSdictionary。 如果我直接在代码中初始化,那么在evey键和值之前,我会需要很多@。 我想避免这种情况。 这就是原因,我把JSON放在一个文件“xyz.txt” 我有两种方法 – 1.我读取表单文件,并使用[[NSDictionary alloc] initWithContentsOfFile:filePath]; 2.我把这个string分配给了NSDictionay。 我一直想避免使用@ 我知道我们可以通过NSData ID结果= [NSJSONSerialization JSONObjectWithData:数据选项:NSJSONReadingMutableContainers错误:&错误]; 但即使在这种情况下,我们将需要使用@初始化string到NSData的所有键和值。 任何解决scheme,可以从文本文件读取JSON和输出分配给NSDictionary { "ABC": [ { "id": "01", "score": "0.2" }, { "id": "02", "score": "0.2" } ], "XYZ": [ { "id": "01", "score": "0.9" }, { "id": "02", "score": "0.9" } ], "PQR": [ { […]

如何在Swift中制作Dyanamic NSDictonary

{ “QuizId” : “23566656” “StartTime”:”23:30” “EndTime”:”23:45” “data”:[ {“QuestionID”:”131313131”,“AnswerID”:“1233152”}, {“QuestionID”:”131313141”,“AnswerID”:“1233152”}, {“QuestionID”:”131313151”,“AnswerID”:“1233152”}, {“QuestionID”:”131313161”,“AnswerID”:“1233152”}, {“QuestionID”:”131313171”,“AnswerID”:“1233152”}, {“QuestionID”:”131313181”,“AnswerID”:“1233152”}, {“QuestionID”:”131313191”,“AnswerID”:“1233152”}, {“QuestionID”:”131313101”,“AnswerID”:“1233152”}, ] } 你好,我想创build一个NSDictonary上运行结构应该是上面。 任何帮助将升值感谢。 我有解决scheme感谢这一努力 我想改变一点,因为我对所有这些数据都有模态。 let info = self.playQuizArray[currentQuizIndex] as! playInfo let Ainfo = info.answers[indexPath.row] as! AnswerInfo let QuesID = info.quizQId for i in 0..<playQuizArray.count { data.append(["QuestionID": QuesID[i], "AnswerID": playQuizArray[i]]) // For Answer Ainfo.ansID } let dic = [ […]

使用NScanner来parsingCSV文件到字典数组

我创build了一个iPhone应用程序,它包含一个位置(lat,long,point)的字典数组。 我通过手动input每个值来创build数组。 myLocationArray = @[ @{ kStation : @"1", kLatitude : @( 41.656467), kLongitude : @(-81.277963) }, @{ kStation : @"2", kLatitude : @(41.657118), kLongitude : @(-81.276545) }, @{ kStation : @"3", kLatitude : @(41.658493), kLongitude : @(-81.273542) }, … 这是好的,但工程,但现在我想通过从.CSV文件获取数据编程创build此数组。 我有一个.CSV文件(TestCSV.csv),看起来像这样。 41.656467,-81.277963,27200 41.657118,-81.276545,27650 41.658493,-81.273542,28631.5 41.660728,-81.268547,30195 41.661830,-81.266065,30991 41.662828,-81.263819,31700 41.663677,-81.261962,32300 41.664578,-81.259909,32950 41.666210,-81.256312,34100 41.666921,-81.254708,34605 41.668043,-81.252191,35400 41.669044,-81.250043,36099 我想通过使用NScannerparsingTestCSV.csv来创buildmyLocationArray(格式如图所示)。 […]

正确的创build新对象的方法是在应用程序委托中定义的NSDictionary和NSArray对象的副本

我想知道什么正确的方法是在应用程序委托或单身人士对象中定义一个对象的副本。 总之,我正在制作一个需要用户login的应用程序。 这个login视图只是一个在“真实”应用程序之上的模式视图控制器,它由一个tabbarcontroller和一些tableview控制器组成。 成功login后,向远程服务器发送数据请求,模式视图控制器被解除,显示包含XML数据的TabBar控制器和表视图。 为了parsing传入的数据,我创build了一个名为DataParser的单例对象,它具有接口 … @interface DataParser : NSObject { // Data objects that hold the data obtained from XML files NSMutableDictionary *personnel; NSMutableDictionary *schedule; NSMutableDictionary *today; } @property (nonatomic, retain) NSMutableDictionary *personnel; @property (nonatomic, retain) NSMutableDictionary *schedule; @property (nonatomic, retain) NSMutableDictionary *today; … 现在,在这些字典中,我存储(可变的)字典和数组,其中包含了parsingXML数据的NSString对象。 由于我不想修改这些原始的对象来保存parsing的数据(也就是说,我只想在login阶段修改它们,而不是在任何的tableview控制器中修改),我正在创build一个新的字典对象,每个tableview控制器上面的一个字典的内容的副本。 所以例如,在一个名为ScheduleViewController的视图控制器的loadView中,我有 … @interface ScheduleViewController : UITableViewController { NSDictionary […]

如何根据元素内部的值将nsdictionary数组分组

我有一个字典数组需要根据作为元素的一部分的PO进行分组,并且也根据相同的PO得到quantityOrdered的总和。 采购订单是dynamic的,这意味着它可以是需要过滤的任何值,并相应地计算出数量。 请帮忙。 { PO = PO2; QuantityReceived = 1; }, { PO = PO1; QuantityReceived = 3; }, { PO = PO1; QuantityReceived = 3; }, { PO = PO3; QuantityReceived = 2; }, { PO = PO2; QuantityReceived = 2; }, { PO = PO3; QuantityReceived = 4; }, { PO = PO1; […]

无法将NSDictionary写入plist文件

更新:当我更改以下行时,我可以写入文件 [infoDict setObject:userList forKey:@"users"]; 至 [infoDict setObject:@"sampleString" forKey:@"users"]; 所以,我试图写入文件的结构一定有问题,有什么想法? 我正在尝试创build一个plist文件,并在运行时在我的iOS应用程序中写入。 我不能写信给它,但我可以阅读。 writeToFile方法返回一个“NO”。 当我手动尝试手动打开我使用Finder创build的文件时,它会显示“无法读取数据,因为它的格式不正确”,这是因为在使用文本编辑器打开文件时,它是空,并且不显示plisttypes的文件应该具有的任何xml标签。 而且我知道我可以从中读取,因为在手动拖动文件夹中的“有效”plist文件时,我的代码能够从那里读取一个空列表。 1)为什么不创build一个有效的plist文件? 和, 2)为什么我不能写(甚至是有效的)plist文件? NSLog(@"* Writing contents to plist file *"); NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString* plistPath = nil; if ((plistPath = [path stringByAppendingPathComponent:@"users.plist"])) { NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL exists = [fileManager fileExistsAtPath:plistPath]; NSLog(exists ? @"yes, file […]

sortingnsdictionary,它是如何工作的?

我在理解compare-using-selector背后的逻辑时遇到了一些麻烦。 我有下面的代码,我试图提取键和sorting他们在同一时间。 但是,它不sorting。 输出NSArray的顺序不会改变,不pipe我做什么。 NSMutableDictionary *dictToSort = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Joe", [NSNumber numberWithInt:2], @"mark", [NSNumber numberWithInt:1], @"mdark", [NSNumber numberWithInt:3], nil]; NSArray *dictToSortKeys = [dictToSort keysSortedByValueUsingSelector:@selector(compare:)]; NSLog(@"Not Sorted" ); NSNumber *xx = dictToSortKeys[0]; NSNumber *xy = dictToSortKeys[1]; NSNumber *xz = dictToSortKeys[2]; NSLog(@"Sorted %d %d %d", xx.integerValue , xy.integerValue, xz.integerValue); 我不明白这个compare:function工作。 它说它返回NSOrderedAscending, NSOrderedSame or NSOrderedDescending ,但是没有办法接收这些返回。 而且,这应该是神奇的工作? 这个比较的文档相当糟糕。

参数types“AnyObject”不符合期望的typesNSCopying

我想在Swift使用NSDictionary ,我正面临着上述问题。 我有一个以下格式的字典: let xyz: NSMutableDictionary = ["1":[1,2,3,4,"1","n","1","2"],"2":[1,2,3,4,"+","o","6","2"]] 我想迭代字典中的键并提取数组的第六个元素。 我尝试了以下; 但没有遇到任何运气: for keys in dictKeyMutableDict { let xCentVal = xyz[keys as! [NSCopying]][6] } 我不断收到一个下标错误,如果我删除as! [NSCopying] as! [NSCopying] ,我收到上面的错误。 有谁知道如何处理这种情况?