Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何通过Objective C从网页中获取Json字符串_Objective C_Json - Fatal编程技术网

Objective c 如何通过Objective C从网页中获取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

我有一个post值到文本字段,它返回JSON字符串,如何post值/接收JSON字符串

这是我的密码:

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