0

I added to the project the file Objects.json which contains the following code:

{
"circle": [
       [1, 3], [2, 1], [3, 2],
],
"line": [
       [2, 1], [3, 2], [1, 3],
],
"A_Letter": [
       [3, 3], [2, 1], [1, 2],
    ],
}

How could I add to this file a new key?

If, for instance, I want to remove the "line" key, how could this be done?

Massimo Piazza
  • 663
  • 3
  • 7
  • 21

2 Answers2

2

Try this may be helpfull, In this I solve JSON and remove key as you wants ..

 NSString *str = @"{\"circle\": [       [1, 3], [2, 1], [3, 2],],\"line\": [       [2, 1], [3, 2], [1, 3],],\"A_Letter\": [       [3, 3], [2, 1], [1, 2],    ]}";
  NSMutableDictionary *datadic = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
  [datadic removeObjectForKey:@"line"];
 NSLog(@"data return %@",datadic);

Thanks

Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
0

Since this is the arrays of dictionary. So for adding into the dictionary use setObject: ForKey: method and for removing use removeObjectForKey: like that below:-

 NSMutableDictionary *mutDict=[yourjsonDict mutableCopy];
 [mutDict setObject: @[@[1,2],@[2,3]] forKey:@"yourKey"];

  // now for removing 
  [mutDict removeObjectForKey:@"line"];
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56