的NSDictionary.如何创建NSDictionary对象

pau*_*991 0 iphone objective-c nsdictionary nsmutabledictionary

我有这个方法.

[self postRequestWithURL: (NSString *) postArgs:(NSDictionary *) headerArgs: (NSDictionary *) ];
Run Code Online (Sandbox Code Playgroud)

我怎样才能正确调用此方法?

网址是: http://www.google.com/reader/api/0/edit-tag?

帖子args是: "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"];
Run Code Online (Sandbox Code Playgroud)

sompne可以帮我插入postArgs和HeaderArgs NSDictionary吗?谢谢保罗

Rud*_*uis 5

尝试这样的事情:

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];
Run Code Online (Sandbox Code Playgroud)

请注意,后面的列表dictionaryWithObjectsAndKeys:包含对象和键的替换,以逗号分隔,后跟最后一个nil,如上例所示.

FWIW,这里的词典是自动释放的,所以你不必明确地发布它们.