当我显示在字典中解析的 JSON 对象的结果然后打印在 alertView 上(在 Xcode 5.1.1 上,在 iphone 64 位模拟器上为 iOS 7.1 编译)时,我发现了一个奇怪的行为。对于相同的输入数据:
[[UIAlertView alloc]initWithTitle:@"something" message:[[[NSString stringWithFormat:@"json:%@",[inputData dictionaryRepresentation]] stringByReplacingOccurrencesOfString:@" "withString:@""]substringToIndex:7035] delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
正确打印,但如果我说“substringToIndex:7036”它只显示空格......没有“stringByReplacingOccurrencesOfString:”方法,限制远远超出:
[[UIAlertView alloc]initWithTitle:@"something" message:[[NSString stringWithFormat:@"json:%@",[inputData dictionaryRepresentation]] substringToIndex:13768] delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
正确打印,而不是“substringToIndex:13769”不打印......我意识到这不是最大长度的问题,而是JSON对象内的特殊字符