I need to remove double quotes from JSON for use in NSDictionary
I have a JSON return that I'm trying to save into a NSDictionary, However, Since there are spaces in the data being returned, the Dictionary won't save this array because of the quote being included. Is there a way to parse the SBJSON to remove the double quotes prior to saving to the rowsArray?
rowsArray: {
Rows = (
{
Children = (
{
Title = Chevy;
},
{
Title = "Red Color";
},
{
Title = "Pre - 1965";
},
{
Title = "White Walls";
},
);
Title = Chevy;
},
Here is the code //JSON NSURL REQUEST for rowsArray
NSURL *url = [NSURL URLWithString:@"http://www.**.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url ]
SBJSON *json = [[SBJSON alloc] init];
NSError开发者_开发知识库 *error = nil;
rowsArray= [json objectWithString:jsonreturn error:&error];
NSLog(@"rowsArray: %@",rowsArray);
//SAVING rowsArray as "FollowingArray.plist"
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path2 = [documentsDirectory stringByAppendingPathComponent:@"FollowingArray.plist"];
[rowsArray writeToFile:path2 atomically:NO];
[jsonreturn release];
[json release];
This works Great and saves if the string where Chevy is, but if the double quotes are in there the .plist won't save
Thanks,
Michael
The easiest way to remove all the quotes would be to use:
-[NSString stringByReplacingOccurrencesOfString: withString:]
like so:
NSString *cleanedString=[jsonreturn stringByReplacingOccurrencesOfString:@"/"" withString:@""];
the "/" is the escape character for the quotes.
精彩评论