我知道 JSON 规范说对象是一组无序的名称/值对。但我真的需要将有序的 JSON 发送到网络服务。问题是:
在网络服务(我不知道或无法访问代码)上,有一个步骤可以将我的 JSON 转换为 SOAP(必须订购所有对象)。
这是我尝试过的:
NSString *json = @"{'perf':1,'begin':'2013-07-17T15:35:33.659-03:00','end':'2013-08-01T15:35:33.659-03:00'}";
NSMutableURLRequest *request = [self requestWithMethod:@"POST"
path:@"/myPath" parameters:nil];
//set headers
NSString *contentType = [NSString stringWithFormat:@"application/json"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
[request addValue:@"any-value" forHTTPHeaderField: @"User-Agent"];
//create the body
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[json dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postBody];
//Add your request object to an AFHTTPRequestOperation
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation,
id responseObject) {
NSString *response = [operation responseString];
NSLog(@"response: [%@]",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", [operation error]);
}];
[operation start];
那么,我该怎么做呢?