IOS application/json file upload, etc., iosjson
In the process of interacting with the sever background, sometimes, they need to be uploaded by iOS developers in the form of "application/json.
NSString * accessUrl = [NSString stringWithFormat: @ "% @/xxx", @ "https://www.xxxxx.com: xxxx"]; NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: accessUrl]; request. HTTPMethod = @ "POST"; // set the request header [request setValue: @ "application/json" forHTTPHeaderField: @ "Content-Type"]; // set the Request body NSMutableData * body = [NSMutableData data]; [body appendData: [jsonStr dataUsingEncoding: Response]; [request setHTTPBody: body]; response * urlResponse = nil; NSError * error = [[NSError alloc] init]; NSData * responseData = [NSURLConnection sendSynchronousRequest: request returningResponse: & urlResponse error: & error]; NSString * result = [[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding]; if (result = nil) {NSLog (@ "json parsing failed! ");} Else {NSData * jsonData = [result dataUsingEncoding: encoding]; NSError * err; NSDictionary * dic = [NSJSONSerialization JSONObjectWithData: jsonData options: Unknown error: & err]; if (err) {NSLog (@ "json parsing failed: % @", err);} success (dic );}