2012-07-26 16 views
0

我一直在試圖使用jsonkit的對象來進行字符串轉換。我的SerializedClasses幫助器將NSMutableArray CellList轉換爲JSONString(ssd日誌)。這完美。然後我把結果字符串放到字典中,然後嘗試獲取jsonstring字典(ssd2 log)。代碼和輸出如下。JSString條出現對象

-(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; 
} 

輸出:

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

爲什麼所有的側隙出現在cellList字符串的中間?

回答

1

它們正在轉義引號字符,因爲它們存在於字符串中。沒有它們,它會告訴解析器保持退出並輸入字符串,並且最終會導致語法無效。