Unexpected "@" in the program

I'm new to iOS development, so I don't find a clue when such an error occurs, the code looks like this:

- (void)postToWall {

    FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]
                              autorelease];
    dialog.userMessagePrompt = @"Enter your message:";
     dialog.attachment = [NSString
                         stringWithFormat:@"{\"name\":\"Facebook Connect for
                         iPhone\",\"href\":\"http://developers.facebook.com/
                         connect.phptab=iphone\",\"caption\":\"Caption\",
                         \"description\":\"Description\",\"media\":[{\"type\":
                         \"image\",\"src\":\"http://img40.yfrog.com/img40/
                      5914/iphoneconnectbtn.jpg\",\"href\":
                         \"http://developers.facebook.com/connect.php?
                         tab=iphone/\"}],\"properties\":{\"another link\":
                         {\"text\":\"Facebook home page\",\"href\":
                             \"http://www.facebook.com\"}}}"];
                         [dialog show];

   }

      

I'm trying to find out from an online tutorial about facebook connection, so I got this error in code and the file includes:

import "FBSession.h" import "FBLoginButton.h"

Do you think this could cause problems?

+3


source to share


3 answers


Either write the line on one line, or add "

to the end and beginning of each line:

dialog.attachment = [NSString
               stringWithFormat:@"{\"name\":\"Facebook Connect for"
               "iPhone\",\"href\":\"http://developers.facebook.com/"
               "connect.phptab=iphone\",\"caption\":\"Caption\","
               "\"description\":\"Description\",\"media\":[{\"type\":"
               "\"image\",\"src\":\"http://img40.yfrog.com/img40/"
               "5914/iphoneconnectbtn.jpg\",\"href\":"
               "\"http://developers.facebook.com/connect.php?"
               "tab=iphone/\"}],\"properties\":{\"another link\":"
               "{\"text\":\"Facebook home page\",\"href\":"
                   "\"http://www.facebook.com\"}}}"];

      



Also note that you don't need to use in this case stringWithFormat

, you can create a string like this:

dialog.attachment = @"{\"name\":\"Facebook Connect for"
           "iPhone\",\"href\":\"http://developers.facebook.com/"
           "connect.phptab=iphone\",\"caption\":\"Caption\","
           "\"description\":\"Description\",\"media\":[{\"type\":"
           "\"image\",\"src\":\"http://img40.yfrog.com/img40/"
           "5914/iphoneconnectbtn.jpg\",\"href\":"
           "\"http://developers.facebook.com/connect.php?"
           "tab=iphone/\"}],\"properties\":{\"another link\":"
           "{\"text\":\"Facebook home page\",\"href\":"
           "\"http://www.facebook.com\"}}}";

      

+3


source


The only thing that seems to be wrong in the code you posted is all the line breaks in the middle of your long line. Also, using stringWithFormat is not required there. Also your first "href" is missing the ?? from a GET request. Try this and see what happens:

dialog.attachment = @"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}";

      



Or better yet, break all your keys and values ​​into their own NSString

and return a long string using stringWithFormat

. Or even BETTER, create everything in memory and use NSJSONSerialization

to create your JSON string. It will be much cleaner and less error prone.

+2


source


I may be wrong, but I think facebook is excluding the dictionary of values ​​for each of these keys.

The sample code is very nice and well documented.

Try replacing "with" between the beginning and end of the line.

-1


source







All Articles