的NSDictionary。如何创建NSDictionary对象

时间:2021-07-26 13:04:48

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?

该网址是: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

post args是:“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:@"GoogleLogin %@", 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

sompne能帮我在NSDictionary中插入postArgs和HeaderArgs吗?谢谢保罗

2 个解决方案

#1


5  

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.

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

FWIW, the dictionaries here are autoreleased, so you don't have to release them explicitly.

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

#2


2  

You could start by reading NSDictionary or NSMutableDictionary documentation. Here's how you'd do it:

您可以从阅读NSDictionary或NSMutableDictionary文档开始。这是你如何做到的:

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];

#1


5  

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.

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

FWIW, the dictionaries here are autoreleased, so you don't have to release them explicitly.

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

#2


2  

You could start by reading NSDictionary or NSMutableDictionary documentation. Here's how you'd do it:

您可以从阅读NSDictionary或NSMutableDictionary文档开始。这是你如何做到的:

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];