Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios JSON序列化后URI值的错误语法错误_Ios_Json_Rest_Tastypie - Fatal编程技术网

Ios JSON序列化后URI值的错误语法错误

Ios JSON序列化后URI值的错误语法错误,ios,json,rest,tastypie,Ios,Json,Rest,Tastypie,对于使用PUT的REST web服务调用,我需要发送如下所示的JSON: {"leader":"John Smith","leader_id":"asldfkj234234324asldkfs234","resource_uri":"/api/event/38001"} 相反,当我序列化JSON时,它会插入额外的“/”字符,这就是为什么我认为会出现400个错误: {"leader":"John Smith","leader_id":"asldfkj234234324asldkfs234","r

对于使用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]; 
}

首先,您的问题与代码不匹配。在您的问题中,您声明您需要发送
“\api\event\38001”
,而在您的代码中您编写了“
/api/event/38001”
。因为你的问题只有在第二种情况下才有意义,所以我认为它是有效的


现在的问题是,JSON序列化程序类会转义斜杠(某些特殊字符需要转义),这就是为什么它会在这些字符之前添加反斜杠。

抱歉,修复了错误。我想我的问题仍然存在,我该如何解决它?thanks@RedRobin您不需要“修复”它。好的,谢谢,我想是其他原因导致了400错误。谢谢