IOS development -- Stage 2 -- Communication -- JSON system parsing, ios -- json
JSON system parsing:
1. Create the Request Path and URL;
2. Construct a request based on the URL. If NSMutableURLRequest is used for POST, the NS variable URL request;
NSMutableURLRequest * mutableURLRequest = [NSMutableURLRequest requestWithURL: url];
3. Build connection 1, synchronize 2, asynchronous;
NSData * responseData = [NSURLConnection sendSynchronousRequest: mutableURLRequest returningResponse: nil error: nil];
4. convert data into strings to check whether the data is correct;
NSString * responseString = [[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding];
NSLog (@ "responseString ___ % @", responseString );
5. Use the system class to parse 1. Data to be parsed 2. Option setting 3. error message;
NSError * error = nil;
NSDictionary * dictionary = [NSJSONSerialization JSONObjectWithData: responseData options: NSJSONReadingMutableContainers error: & error];
NSLog (@ "dictionary ____ % @", dictionary );
NSLog (@ "% d _______ % @", error. code, error. localizedDescription );