Tôi đang đọc dữ liệu chuỗi từ PLIST mà tôi đang sử dụng để tạo chuỗi JSON (tình cờ sử dụng trong Facebook Connect).Phân tích cú pháp NSStrings để đảm bảo chuỗi JSON được định dạng chính xác trong XCode
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];
Tất cả điều này hoạt động tốt, nhưng một số mô tả sự kiện nhất định (4 trong số khoảng 150) văn bản xuất hiện trong hộp thoại trống. Câu hỏi của tôi là, có một cuộc gọi phương thức dễ dàng, chẳng hạn như stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding sẽ đảm bảo rằng bất kỳ ký tự tinh quái nào được thoát hay bỏ qua?
Cảm ơn trước,
Dave
Thực tế về điều tra thêm, biểu tượng bản quyền là không đúng, đó là LF/CR thực tế trong văn bản cho 2 sự kiện và "ký tự cho sự kiện khác 2. –