-1

I have an array storing some attributes (those attributes are: tableID(string), tables coordinate(x,y coordinate in float)). Does anyone know how to store this array into NSMutableDictionary? And I need this NSMutableDictionary transfer into JSON string.

Girish
  • 4,692
  • 4
  • 35
  • 55
ISAAC
  • 3
  • 3
  • To convert a dictionary to JSON, all keys must be strings so you can't use an array as a key. – rmaddy Jun 25 '13 at 03:53
  • Keys for dictionaries must also be immutable. – dreamlax Jun 25 '13 at 03:56
  • oh.. this mean i cant add array into dictionary as a key? but this array is important to me because i got many tables attribute inside. i know how to convert all values inside to string, but i'm not sure how to use add array object to dictionary. – ISAAC Jun 25 '13 at 03:58
  • dreamlax - yup, my keys for dictionary will be immutable. – ISAAC Jun 25 '13 at 03:59
  • @dreamlax Keys do not need to be immutable though they usually are. – rmaddy Jun 25 '13 at 04:09
  • @ISAAC You can store the array in the dictionary but it must be stored as a value, not a key. – rmaddy Jun 25 '13 at 04:10
  • @rmaddy oh i get what you mean.. i store my array as value, and i set my key myself? – ISAAC Jun 25 '13 at 04:17
  • @ISAAC Sure, see the answer by Satish. – rmaddy Jun 25 '13 at 04:19
  • @rmaddy: They don't need to be strictly immutable, but they can't mutate in a way that affects `isEqual:` and `hash`. – dreamlax Jun 25 '13 at 05:00

1 Answers1

1

You can Simply set ur MUtable Array in MUtable Dictionary like

NSMutableDictionary *muteDict = [[NSMutableDictionary alloc] init];

   [muteDict setObject:mutableArrayObject  forKey:@"YourKey"];
Satish Azad
  • 2,302
  • 1
  • 16
  • 35
  • @ISAAC: FYI, this will actually create an immutable copy of the array rather than adding the mutable array itself as a key. – Chuck Jun 25 '13 at 06:30