Objective c 如何通过Objective C从网页中获取Json字符串
我有一个post值到文本字段,它返回JSON字符串,如何post值/接收JSON字符串 这是我的密码:Objective c 如何通过Objective C从网页中获取Json字符串,objective-c,json,Objective C,Json,我有一个post值到文本字段,它返回JSON字符串,如何post值/接收JSON字符串 这是我的密码: NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.donxebuyt.com/"]]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setPostValue:txtFrom.text
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.donxebuyt.com/"]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:txtFrom.text forKey:@"id_locA"];
[request setRequestMethod:@"POST"];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
NSLog(@"Response: %@", responseString);
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"Error: %@", error.localizedDescription);
}];
[request startAsynchronous];
iOS有一个内置的json序列化框架(只需在项目中包含json.framework),或者有一些开源框架,如JSONKit:
sth
是一个新变量,在上面发布时发布它
NSData *data=[NSData dataWithContentsOfURL:url];
NSError *error=nil;
NSDictionary *response=[NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:&error];
NSString* sth=[response objectForKey: @"some_your_key"];