Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Objective c 将AshittpRequest设置为NSDictionary_Objective C_Ios4_Nsdictionary_Asihttprequest - Fatal编程技术网

Objective c 将AshittpRequest设置为NSDictionary

Objective c 将AshittpRequest设置为NSDictionary,objective-c,ios4,nsdictionary,asihttprequest,Objective C,Ios4,Nsdictionary,Asihttprequest,我正在尝试将NSDictionary发送到服务器,并按如下方式进行设置: NSDictionary *songInfo = [[NSDictionary alloc] initWithObjects:propertyValues forKeys:propertyKeys]; NSURL *exampleURL = [NSURL URLWithString:@"http://www.example.com/activities"]; ASIFormDataRequest *request = [

我正在尝试将NSDictionary发送到服务器,并按如下方式进行设置:

NSDictionary *songInfo = [[NSDictionary alloc] initWithObjects:propertyValues forKeys:propertyKeys];

NSURL *exampleURL = [NSURL URLWithString:@"http://www.example.com/activities"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:exampleURL];

[request setValuesForKeysWithDictionary:songInfo];
[request startAsynchronous];
我得到以下错误:

[<ASIFormDataRequest 0x1035600> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 1 Media Type.
[setValue:forUndefinedKey:]:此类不符合密钥1媒体类型的密钥值编码。
这是令人费解的,因为媒体类型是字典中的第14个键,所以它怎么可能与所有其他的都很好,然后就在这个问题上发疯了


它似乎不接受我的字典,但有什么原因吗?

有几个原因:

  • 字典中的键没有顺序。没有“字典中的第14个键”这样的东西。必须序列化字典条目以进行日志记录,但不能保证其他方法会以相同的顺序访问它们
  • 无论是
    ASIFormDataRequest
    还是
    ASIHTTPRequest
    都不会覆盖
    -setValueForKeysWithDictionary:
    -setvalueforkey:
    。这意味着,除非键与对象的键值编码兼容键匹配,否则您将看到该异常
尝试使用受支持的方法,如
-setPostValue:forKey:

NSDictionary *songInfo = /*...*/;
ASIFormDataRequest *request = /*...*/;
[songInfo enumerateKeysAndObjectsUsingBlock:
^(id key, id value, BOOL *stop) {
    [request setPostValue:value forKey:key];
}];

将来:使用。

什么是属性值和属性键?里面是什么?我也从未尝试过将setValuesForKeysWithDictionary与ASIFormDataRequest一起使用,因为该方法来自NSOperation。您是否尝试过仅使用addPostValue?那么,我如何在不单独分配每个帖子和关键字的情况下轻松地将字典的内容放入请求中?如果您可以更新web服务来处理它,您可以使用
+[NSKeyedArchiver archivedDataWithRootObject:
将字典存档到
NSData
,这意味着字典中的所有内容都必须符合
NSCoding
,您的web服务必须能够访问相同的类来解码存档,或者使用
NSPropertyListSerialization
类将字典序列化为plist,这意味着字典中的所有内容都必须仅使用plist类型进行序列化。任何web服务都应该能够反序列化XML plist。我不想通过XML发送它,而是作为http变量发送。存档是否仍适用于此?请提供一个指定“HTTP变量”的参考。除了将归档对象归档为苹果的私有格式之外,归档实际上不适用于任何其他用途。我对“将内容发送到服务器”这一整件事还不熟悉,不知道HTTP变量是什么。我只是被要求这样发送它们,我完全不明白这意味着什么。对不起,我帮不上忙。