我想从我的iPhone应用程序发布文本到我在Facebook上的墙上。一切工作正常,但是,我的问题是,我不知道如何格式化文本。我想向用户展示他们在应用中查看的餐厅的名称,地址,城市,州和电话号码。这里是我的相关代码:如何在Objective-C中进行字符串格式化?
- (void)postToWall {
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ got straight A's!\",\"href\":\"http://www.example.com/\",\"caption\":\"%@ must have gotten real lucky this time!\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.abc.png\",\"href\":\"http://www.example.com/\"}]}",
_facebookName, _facebookName];
dialog.actionLinks = @"[{\"text\":\"Download GetHalal!\",\"href\":\"http://www.example.com/\"}]";
[dialog show];
}
我想显示用户在dialog.attachment变量的餐厅信息,使得在Facebook涂鸦墙输出看起来是这样的:
restaurant.name restaurant.address restaurant.city,restaurant.state restaurant.phoneNumber
我的问题是,上面的文本似乎是在JSON格式。餐厅对象在课堂上可用,我想将它包含在上面的代码中,但我不知道如何。任何人都可以告诉我如何做到这一点?
非常感谢您的帮助。非常感激! – syedfa 2011-04-18 06:09:36