从iPhone发布到Facebook时,在JSON中使用新的换行符序列

时间:2011-04-18 18:39:52

标签: iphone objective-c json escaping

我正在开发一个将餐馆信息发布到用户Facebook墙上的应用程序。一切正常,但我不知道如何在JSON代码的“description”部分中插入新行。我的相关代码如下:

FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Check out this great restaurant!\",\"href\":\"/\",\"caption\":\"%@\",\"description\":\"%@ /*NEW LINE HERE*/%@, %@ /*NEW LINE HERE*/%@\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.myhost.ca/images/image_IC_B_03.png\",\"href\":\"http://www.myhost.com/\"}]}",
                     restaurantObj.name, restaurantObj.address, restaurantObj.city, restaurantObj.provinceState, restaurantObj.phoneNumber];
dialog.actionLinks = @"[{\"text\":\"Download this app!\",\"href\":\"http://www.myhost.com/\"}]";

[dialog show];

我试图插入\ n而且我试图在我上面标记的地方插入\ r \ n,但不幸的是,这不起作用。有人有解决方案吗?

1 个答案:

答案 0 :(得分:0)

您可以使用与此人相同的解决方法:

facebook c# sdk: Add/edit event with newlines in description