anyone know how to convert a NSMutableArray to NSString?
What I want to do is, convert the NSMutableArray to a NSString and then store the string.
Im just having a problem with the converting.
Thanks alot!
(Later on I will of course have to convert the string back to the NSMutableArray!)
The array contains arrays, dictionarys and strings.
I would like to convert it all to a string, store it in the Keychain and be able to reverse the whole thing.
What is the purpose of converting it all to a string and then back? Are you trying to display it somewhere or are you just trying to save it?
Well, the user is able to add Dictionarys with strings attatched in any number he likes.
I want to add the whole 'data.plist' to the keychain. And for that I have to convert it all to strings first.
NSMutableString* stringEncodedPlist = [[NSMutableString alloc] init];
for( NSDictionary* item in root )
{
NSArray* contentAry = [item objectForKey:@"content"];
NSString* name = [contentAry objectAtIndex: 1];
NSDictionary* subItem = [contentAry objectAtIndex: 0 ];
NSString* subText = [subItem objectForKey:@"Text"];
NSString* subName = [subItem objectForKey: @"Name"];
//here you want to combine all the elements
NSString* result = [NSString stringWithFormat:@"****%@****%@****%@", subText, subName, name];
[stringEncodedPlist appendString: [NSString stringWithFormat:@"%@^^^", result];
}
//do other stuff
[stringEncodedPlist release];
Now you should have a string where each "Item" in your plist is sepearted by '^^^'. Then within each "Item", the contents of the "Content" array, and the "Name" should all be separated by "***". I'm sure you can easily reverse this operation without me having to explain it.
By the way, I havent tested this, it's just a shot in the right direction, but theoretically it should work, although it may not be the best solution.
I don't want to bother you again but would it be possible to also give me the code to reverse that? Your code worked out so well that I would love to have it. Thanks alot again!