NSArray的词典

时间:2015-07-16 11:49:27

标签: ios objective-c nsarray nsdictionary

NSArray NSDictionaries JSON来自服务器NSDictinoary格式。我想再向NSarray NSdictionaries添加一个NsdictionaryTable = ( { Name = “xyz”; Recordid = 3; prefrenceorder = 1; }, { Name = “ABC”; Recordid = 2; prefrenceorder = 2; }, { Name = “swe”; Recordid = 450; prefrenceorder = 3; }, { Name = “asd”; Recordid = 451; prefrenceorder = 4; } ); 基于键值对。这是我得到的回应。我想在" table"中添加另一个相同格式的字典。请帮助..

提前致谢.. !!

    Exception in thread "main" org.apache.hadoop.ipc.RemoteException: Server IPC version 9 cannot communicate with client version 4
at org.apache.hadoop.ipc.Client.call(Client.java:1066)
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:225)
at com.sun.proxy.$Proxy1.getProtocolVersion(Unknown Source)
at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:396)
at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:379)
at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:118)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:222)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:187)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:89)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1328)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:65)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1346)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:244)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:187)
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.setInputPaths(FileInputFormat.java:352)
at pir.PIR.run(PIR.java:317)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at pir.PIR.main(PIR.java:256)

3 个答案:

答案 0 :(得分:1)

由于来自服务器的NSArray是不可变的,所以你需要创建一个新的NSMutableArray实例来添加你自己的字典,其响应来自服务器。

NSMutableArray *newTable = [NSMutableArray arrayWithArray:Table];
[newTable addObject:your_new_dictionary];

答案 1 :(得分:1)

NSDictionary放入NSMutableArray。然后从您的实例添加新对象NSDictionary

//The array which has your NSDictionary objects
NSArray *array;

//Putting this array into mutable one in order to add and delete elements
NSMutableArray *mArray = [array mutableCopy];

//Your custom object that you want to add
NSDictionary *yourObject;

//Add it to the array and voila
[mArray addObject:yourObject];

答案 2 :(得分:0)

最好不要将不可变数组转换为可变数组,而是使用适当的NSJSONSerialization选项 - NSJSONReadingMutableContainers

  

指定将数组和字典创建为可变对象。

NSMutableArray *mutableArray = [NSJSONSerialization JSONObjectWithData:yourData options:NSJSONReadingMutableContainers error:nil];
[mutableArray addObject:yourNewDictionary];
相关问题