Question

I´ve been trying to use jsonkit for a object to string convertion. My SerializedClasses helper converts a NSMutableArray CellList into a JSONString (ssd log). This goes perfectly. Then I put the resultant string in a dictionary and then try to get the jsonstring dictionary (ssd2 log). The code and output follow.

    -(NSDictionary*)toDictionary{ 
NSString *myCellListString = [SerializedClassesHelper cellListToString:cellList];
NSLog(@"ssd:%@",myCellListString);

    NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                              [[NSString alloc] initWithFormat:@"%@",myCellListString],@"cellList",
                              [[NSString alloc] initWithFormat:@"%d",weaponType],@"weaponType",
                              nil];

for (NSString *eachString in myDictionary) {
    [eachString release];
}
NSLog(@"ssd2:%@",[myDictionary JSONString]);
return myDictionary;
}

Output:

ssd:[{"col":"4","row":"2"},{"col":"4","row":"2"}]
ssd2:{"weaponType":"0","cellList":"[{\"col\":\"4\",\"row\":\"2\"},{\"col\":\"4\",\"row\":\"2\"}]"}

Why are all those backlashes appearing in the middle of the cellList string?

Was it helpful?

Solution

They are escaping the quote characters, because they are present inside a string. Without them, it would tell the parser to keep exiting and entering the string, and you'd end up with invalid syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top