对于使用 PUT 的 REST Web 服务调用,我需要发送如下所示的 JSON:
{"leader":"John Smith","leader_id":"asldfkj234234324asldkfs234","resource_uri":"/api/event/38001"}
相反,当我序列化 JSON 时,它会插入额外的 '/' 字符,这就是我相信我收到 400 错误的原因:
{"leader":"John Smith","leader_id":"asldfkj234234324asldkfs234","resource_uri":"\/api\/event\/38001"}
这是我正在使用的代码。有任何想法吗?
NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
self.clubToEdit.leader, @"leader",
self.clubToEdit.leaderID, @"leader_id",
@"/api/event/38001", @"resource_uri",
nil];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myDictionary options:0 error:&error];
if (!jsonData)
{
NSAssert(FALSE, @"Unable to serialize JSON from NSDict to NSData");
} else {
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
RKParams *params = [RKRequestSerialization serializationWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]MIMEType:RKMIMETypeJSON];
[client put:@"/api/event/?format=json&username=test&api_key=apikey" params:params delegate:self];
}