Objective c 表单字典作为PUT API请求中的参数-AFNetworking
嗨,我必须使用RESTAPI将我的记录更新到服务器。 我正在使用AFNetworking库并形成PUT请求参数格式,如下所示Objective c 表单字典作为PUT API请求中的参数-AFNetworking,objective-c,nsdictionary,afnetworking-2,Objective C,Nsdictionary,Afnetworking 2,嗨,我必须使用RESTAPI将我的记录更新到服务器。 我正在使用AFNetworking库并形成PUT请求参数格式,如下所示 { "type":"goal", "field_weight_goal": { "und": [ { "value": "60" } ] }, "field_weight_actual": { "und": [
{
"type":"goal",
"field_weight_goal": {
"und": [
{
"value": "60"
}
]
},
"field_weight_actual": {
"und": [
{
"value": "90"
}
]
},
"field_weight_date": {
"und": [
{
"value": "05-10-2017",
"format": null,
"safe_value": "05-10-2017"
}
]
}
}
{
"field_weight_actual" = {
und = (
{
value = "100.0";
}
);
};
"field_weight_date" = {
und = (
{
format = "<null>";
"safe_value" = "04-18-2017";
value = "04-18-2017";
}
);
};
"field_weight_goal" = {
und = (
{
value = "90.0";
}
);
};
type = goal;
}
下面是我的代码
NSDictionary *params = @{@"type": @"goal",
@"field_weight_goal" : @{@"und": @[ @{@"value": self.goalWeightTextField.text } ] },
@"field_weight_actual" : @{@"und": @[ @{@"value": self.currentWeightTextField.text } ] },
@"field_weight_date" : @{@"und": @[ @{@"value": currentDate, @"format" : [NSNull null] , @"safe_value" : currentDate } ] }
};
服务器中的值未更新,我收到错误。。。请求失败:不可接受(406)。请帮我更正我的字典格式。
在xcode中调试时,我的参数格式如下
{
"type":"goal",
"field_weight_goal": {
"und": [
{
"value": "60"
}
]
},
"field_weight_actual": {
"und": [
{
"value": "90"
}
]
},
"field_weight_date": {
"und": [
{
"value": "05-10-2017",
"format": null,
"safe_value": "05-10-2017"
}
]
}
}
{
"field_weight_actual" = {
und = (
{
value = "100.0";
}
);
};
"field_weight_date" = {
und = (
{
format = "<null>";
"safe_value" = "04-18-2017";
value = "04-18-2017";
}
);
};
"field_weight_goal" = {
und = (
{
value = "90.0";
}
);
};
type = goal;
}
{
“现场重量实际值”={
und=(
{
value=“100.0”;
}
);
};
“字段重量日期”={
und=(
{
格式=”;
“安全值”=“04-18-2017”;
value=“04-18-2017”;
}
);
};
“场地重量目标”={
und=(
{
value=“90.0”;
}
);
};
类型=目标;
}
确保将数据序列化为json,并确保将内容类型设置为jsonIt从字典中删除@[{@“value”时显示错误,使用此代码添加内容类型manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@“application/json”]
实际上我搞糊涂了。我认为你的字典格式不好。我面前没有mac系统。因此我无法测试。请阅读有关字典的内容。在控制台中打印。@PhaniRaghu请查看我共享的调试格式确保将数据序列化为json,并确保将内容类型设置为jsonIt在重新启动时显示错误将@from dictionary@[{@“value”移动到代码中以添加内容类型manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@“application/json”]
实际上我搞糊涂了。我认为你的字典格式不好。我面前没有mac系统。因此我无法测试。请阅读有关字典的内容。在控制台中打印。@PhaniRaghu请查看我共享的调试格式