0
對於使用PUT一個REST Web服務調用後URI值,我需要發送JSON看起來像這樣:錯誤的語法錯誤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];
}
對不起,固定的錯字。我想我的問題仍然有效,如何解決呢?謝謝 – RedRobin
@RedRobin你不要「修復」它 – 2012-09-23 05:24:54
好的謝謝,我猜別的東西是扔400錯誤。 – RedRobin