如何反序列化json对象并分配给iOS中的NSDictionary

这是我处理服务器响应的代码。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"connectionDidFinishLoading : %@", [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]); } 

这是服务器对我的响应,NSLog JSON显示在控制台中。

 connectionDidFinishLoading : {"ErrorCode":"CssParameterException","ErrorMessage":"An error has occurred, please try again later.","Success":false} 

我的问题是:我如何反序列化JSON并将其存储到本地variablesNSDictionary *jsonData

有什么build议么? 请给我一些代码示例,谢谢!

 NSError *e = nil NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData: responseData options: NSJSONReadingMutableContainers error: &e]; 

如果你有NSString响应

 NSError *e = nil NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData: [responseString dataUsingEncoding:NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: &e]; 
Interesting Posts