NSDictionary. How to create NSDictionary object
I have this method.
[self postRequestWithURL: (NSString *) postArgs:(NSDictionary *) headerArgs: (NSDictionary *) ];
How can I correctly call this method?
the url is: http://www.google.com/reader/api/0/edit-tag?
the post args are: "a=user/-/state/com.google/read&ac=edit-tags&s=feed/%@&i=%@&T=%@", entry.link, entry.identifier, tokenString
and header are:
NSString *authHeader = [NSString stringWithFormat:@"Goog开发者_开发知识库leLogin %@", authString];
[thttpReq addValue:authHeader forHTTPHeaderField:@"Authorization"];
[thttpReq addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"];
Can sompne help me to insert postArgs and HeaderArgs in a NSDictionary
?
Thanks
Paolo
Try something like this:
NSDictionary *postArgs = [NSDictionary dictionaryWithObjectsAndKeys:
@"user/-/state/com.google/read", @"a",
@"edit-tags", @"ac",
[NSString stringWithFormat: @"feed/%@", entry.link], @"s",
[NSString stringWithFormat: @"%@", entry.identifier], @"i",
[NSString stringWithFormat: @"%@", tokenString], @"T",
nil];
NSDictionary *headerArgs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat: @"GoogleLogin %@", authString], @"Authorization",
@"application/x-www-form-urlencoded", @"Content-Type"
nil];
[self postRequestWithURL: @"http://www.google.com/reader/api/0/edit-tag"
postArgs: postArgs
headerArgs: headerArgs];
Note that the list after dictionaryWithObjectsAndKeys:
contains alternations of objects and keys, separated by commas, followed by a final nil
, as in the example above.
FWIW, the dictionaries here are autoreleased, so you don't have to release them explicitly.
You could start by reading NSDictionary or NSMutableDictionary documentation. Here's how you'd do it:
NSString * feed = [NSString stringWithFormat: @"feed/%@&i=%@&T=%@", entry.link, entry.identifier, tokenString];
NSDictionary * parameters = [[NSDictionary alloc] initWithObjectsAndKeys: @"a", @"user/-/state/com.google/read", @"ac", @"edit-tags", @"s", feed, nil];
精彩评论