NSString *username = @"username";
NSString *password = @"password";
NSURL *loginurl = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.reddit.com/api/login/%@",username]];
NSMutableURLRequest *loginrequest = [NSMutableURLRequest requestWithURL:loginurl];
[loginrequest setHTTPMethod:@"POST"];
NSData *loginRequestBody = [[NSString stringWithFormat:@"api_type=json&user=%@&passwd=%@",username,password] dataUsingEncoding:NSUTF8StringEncoding];
[loginrequest setHTTPBody:loginRequestBody];
NSURLResponse *loginResponse = NULL;
NSError *loginRequestError = NULL;
NSData *loginResponseData = [NSURLConnection sendSynchronousRequest:loginrequest returningResponse:&loginResponse error:&loginRequestError];
NSString *loginResponseString = [[NSString alloc]initWithData:loginResponseData encoding:NSUTF8StringEncoding];
NSLog(@"%@",loginResponseString);
NSLog 打印:(替换了一些字母)
{“json”:{“错误”:[],“数据”:{“modhash”:“j5hq16ukw2f17a9c153xxxxxxxxxa72ad989c96c904d49a97e”,“cookie”:“13986184,2012-07-14T12:41:05,349f968b3089af75978xxx}xxx}xxx7ba
我如何访问 modhash 和 cookie?我试过
[loginResponseData valueForKey:@"json"];
但它表示该类不符合键 json 的键值编码