Iphone 国家统计局词典。如何创建NSDictionary对象
我有这个方法Iphone 国家统计局词典。如何创建NSDictionary对象,iphone,objective-c,nsdictionary,nsmutabledictionary,Iphone,Objective C,Nsdictionary,Nsmutabledictionary,我有这个方法 [self postRequestWithURL: (NSString *) postArgs:(NSDictionary *) headerArgs: (NSDictionary *) ]; 如何正确调用此方法 url是:http://www.google.com/reader/api/0/edit-tag? post参数是:“a=user/-/state/com.google/read&ac=edit tags&s=feed/%@&i=%@&T=%@”、entry.link、
[self postRequestWithURL: (NSString *) postArgs:(NSDictionary *) headerArgs: (NSDictionary *) ];
如何正确调用此方法
url是:http://www.google.com/reader/api/0/edit-tag?
post参数是:“a=user/-/state/com.google/read&ac=edit tags&s=feed/%@&i=%@&T=%@”、entry.link、entry.identifier、tokenString
标题和标题为:
NSString *authHeader = [NSString stringWithFormat:@"GoogleLogin %@", authString];
[thttpReq addValue:authHeader forHTTPHeaderField:@"Authorization"];
[thttpReq addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"];
sompne能帮我在NSDictionary
中插入postArgs和HeaderArgs吗?
谢谢
保罗你可以从阅读或文档开始。以下是您的做法:
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];
试着这样做:
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];
请注意,dictionaryWithObjectsAndKeys:
后面的列表包含对象和键的交替,用逗号分隔,后跟最后的nil
,如上面的示例所示
FWIW,这里的字典是自动删除的,所以您不必显式地发布它们。查看我的答案。我认为
内容类型
是关键,应用程序/x-www-form-urlencoded
是价值,而不是相反。