//模型转字典
NSDictionary*modelDict = [selfgetPropertyDict:_registerModel];
//字典转json数据
NSData*jsonData = [NSJSONSerializationdataWithJSONObject:modelDictoptions:0error:nil];
NSLog(@"jsonData : %@", [[NSStringalloc]initWithData:jsonDataencoding:NSUTF8StringEncoding]);
NSString*regiseterStr = [[GetUrlStringsharedManager]urlWithRegister];
NSURL*registerURL = [NSURLURLWithString:regiseterStr];
NSMutableURLRequest*request = [NSMutableURLRequestrequestWithURL:registerURL];
[requestsetHTTPMethod:@"POST"];
[requestsetHTTPBody:jsonData];
NSURLSession*session = [NSURLSessionsharedSession];
NSURLSessionDataTask*task = [sessiondataTaskWithRequest:requestcompletionHandler:^(NSData*_Nullabledata,NSURLResponse*_Nullableresponse,NSError*_Nullableerror) {
if(!error) {
NSDictionary*resultDict = [NSJSONSerializationJSONObjectWithData:dataoptions:0error:nil];
NSString*info = resultDict[@"info"];
[selfdisplayAlertControllerWithMessage:info];
}
}];
[taskresume];
其中jsonData输出:{"county":"东城区","password":"jimg","userName":"jimg","city":"北京","mobile":"23456458","memberType":"1","regCode":"234577","province":"北京"};
info: A JSONObject text must begin with '{' at character 1 of %7B%22county%22%3A%22%E4%B8%9C%E5%9F%8E%E5%8C%BA%22%2C%22password%22%3A%22jimg%22%2C%22userName%22%3A%22jimg%22%2C%22city%22%3A%22%E5%8C%97%E4%BA%AC%22%2C%22mobile%22%3A%2223456458%22%2C%22memberType%22%3A%221%22%2C%22regCode%22%3A%22234577%22%2C%22province%22%3A%22%E5%8C%97%E4%BA%AC%22%7D=
怎么回事???
网友评论