出现JSString条的对象

时间:2012-07-26 16:01:59

标签: iphone nsdictionary jsonkit

我一直在尝试使用jsonkit将对象转换为字符串。我的SerializedClasses助手将NSMutableArray CellList转换为JSONString(ssd日志)。这很完美。然后我将结果字符串放在字典中,然后尝试获取jsonstring字典(ssd2 log)。代码和输出如下。

    -(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 个答案:

答案 0 :(得分:1)

他们正在转义引号字符,因为它们存在于字符串中。没有它们,它会告诉解析器继续退出并输入字符串,并且最终会出现无效的语法。