我在字典中有一些数据,比如
NSMutableDictionary *jsonDictionary;
jsonDictionary = [[NSMutableDictionary alloc] init];
[jsonDictionary setValue:@"XYZ" forKey:@"CommandType"];
[jsonDictionary setValue:@"ABC" forKey:@"AppID"];
[jsonDictionary setValue:@"PQM" forKey:@"UserName"];
NSURLResponse *response;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&error];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"Http://SomeURL"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: jsonData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [jsonData length]] forHTTPHeaderField:@"Content-Length"];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *serverResponse = (NSString *)[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSMutableDictionary *results = [serverResponse JSONValue];
在我的“结果”中,我得到了 null .. 它有什么问题并向我显示 consol 中的错误。错误如下。
-JSONRepresentation failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=4 \"Not valid type for JSON\" UserInfo=0x6b8d880 {NSLocalizedDescription=Not valid type for JSON}"
-JSONFragment failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=1 \"JSON serialisation not supported for NSMutableURLRequest\" UserInfo=0x6b8ddf0 {NSLocalizedDescription=JSON serialisation not supported for NSMutableURLRequest}"
任何可以帮助我解决这个问题。