我已使用SBJsonParser
和ASIFormDataRequest
进行发布和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中执行此操作。 以上方法一切正常......
答案 0 :(得分:0)
NSJSONSerialization
中只有几种方法。看一下文档。
json_dic_values = [NSJSONSerialization JSONObjectWithData: [response dataUsingEncoding: NSUTF8StringEncoding] options: 0 error: &error];