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?

1
  • 2
    You'd need to parse the JSON, modify the result, then reserialise it. Commented Jun 28, 2014 at 11:08

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! I'm going to try this
It's working fine in my code. I have tested this .. thanks and accept my answer :)
also can accept on click right arrow ...
-1 for not checking for errors.
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"];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.