2011-04-17 44 views
0

我想从我的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格式。餐厅对象在课堂上可用,我想将它包含在上面的代码中,但我不知道如何。任何人都可以告诉我如何做到这一点?

回答

2

使用JSON库:

https://stackoverflow.com/questions/286087/best-json-library-to-use-when-developing-an-iphone-application

此外,检查iOS版的Facebook SDK:

http://developers.facebook.com/docs/guides/mobile/#ios

在这个StackOverflow的岗位接受的答案有你需要的代码,用JSONfragment:

How to post a message with attachment in Facebook?

(请注意,在这种情况下,使用的库是http://code.google.com/p/json-framework/

+0

非常感谢您的帮助。非常感激! – syedfa 2011-04-18 06:09:36