2016-04-03 49 views
0

我有以下代码来获取json和存储在nsstring中,但我想存储在nsdictionary中..我尝试了一些方法没有我的解决方案..help我在此先感谢我可以得到json和我存储在nsstring中,但我想存储在nsdictionary中的nsstring数据

[request setHTTPMethod:@"GET"]; 
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; 
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 

    NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 

    NSString *outfinal=[requestReply stringByReplacingOccurrencesOfString:@"\\""" withString:@""]; 

      NSLog(@"sender id array: %@", outfinal); 




}] resume]; 

回答

0

尝试:

NSDictionary * json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; 
              NSLog(@"%@",json); 
0

尝试以下方法,它绝对可以帮助你。不要忘记替换URL

NSURL *url = [[NSURL alloc] initWithString:@"Replace your URL here"]; 

[NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:url] queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{ 
    NSMutableArray * jsonData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; 
    if (error) 
     NSLog(@"JSONObjectWithData error: %@", error); 
    else 
     { 
    // Enter your code here to use Json Objects Store in JsonData(NSMutablearray) 
    }); 
}]; 

检索存储在数组对象,使用的值下面的代码:

[[jsonData objectAtIndex:0] objectForKey:@"Key for retrieving value from Object"]; 
+0

喜真的感谢您的回复,并正在使用iOS9所以当我使用NSURLConnection的它iOS9显示过时的..所以是它显示任何错误给我? –

相关问题