我正在从PLIST中读取字符串数据,该字符串数据用于创建JSON字符串(顺便在Facebook Connect中使用)。解析NSString以确保XCode中正确形成的JSON字符串
NSString *eventLink = [eventDictionary objectForKey:EVENT_FIND_OUT_MORE_KEY];
NSString *eventLinkEscaped = [eventLink stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *eventName = [eventDictionary objectForKey:EVENT_NAME_KEY];
NSString *eventDescription = [eventDictionary objectForKey:@"Description"];
NSString *eventImageAddress = [eventDictionary valueForKey:@"Image URL"];
if ([eventImageAddress length] == 0)
{
eventImageAddress = NO_EVENT_IMAGE_URL;
}
// Publish a story to the feed using the feed dialog
FBStreamDialog *facebookStreamDialog = [[[FBStreamDialog alloc] init] autorelease];
facebookStreamDialog.delegate = self;
facebookStreamDialog.userMessagePrompt = @"Publish to Facebook";
facebookStreamDialog.attachment =[NSString stringWithFormat: @"{\"name\":\"%@\",\"href\":\"%@\",\"description\":\"%@\",\"media\":[{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"}]}", eventName, eventLinkEscaped, eventDescription, eventImageAddress, eventLinkEscaped];
[facebookStreamDialog show];
所有这些都很好,但某些事件描述(大约150中有4个)出现在对话框中的文本是空白的。我已经找到了明显的候选人,即描述包含“字符为例或版权符号。我的问题是,是否有一个简单的方法调用,如stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding,将确保任何躲闪或忽略任何躲闪?
由于提前,
戴夫
其实在进一步的调查中,版权符号是好的这是实际LF/CR文本为事件2和“字符为其他2 – 2010-02-10 11:12:17