NSJsonSerialization Post请求方法

时间:2013-05-30 14:17:21

标签: ios objective-c nsjsonserialization

我已使用SBJsonParserASIFormDataRequest进行发布和JSON解析,例如

NSString *urlStr = @"http:facebookpage/second/index.php";
NSURL *log_Url = [NSURL URLWithString:urlStr];

request = [ASIFormDataRequest requestWithURL:log_Url];
[ASIHTTPRequest setSessionCookies:nil];
[request setPostValue:uName.text forKey:@"uname"];
[request setPostValue:passWord.text forKey:@"pwd"];
[request setPostValue:@"login" forKey:@"req"];
[request startSynchronous];

NSError *error = [request error];
if (!error) {
    response = [request responseString];
}
NSLog(@"%@",response);

然后为解析:

parser = [[SBJsonParser alloc]init ];
json_dic_values = [parser objectWithString:response error:nil];
NSString *status = [json_dic_values objectForKey:@"status"];
Url_pathforPages = [json_dic_values objectForKey:@"url"];
NSString *sessionID = [json_dic_values objectForKey:@"session_id"];

在这里,我需要知道如何在NSJsonSerialization中执行此操作。 以上方法一切正常......

1 个答案:

答案 0 :(得分:0)

NSJSONSerialization中只有几种方法。看一下文档。

json_dic_values = [NSJSONSerialization JSONObjectWithData: [response dataUsingEncoding: NSUTF8StringEncoding] options: 0 error: &error];