我关注this tutorial创建RESTful Web服务应用程序。我只使用简单的字符串通过其指令成功创建了GET,POST和DELETE。但是,我现在正在尝试使用“复杂”类(只有2个字符串)自己创建一个PUT方法,无论我读到多少关于null的页面,似乎没有任何东西可以正确使用。我很确定问题出在我的JSON发送端(使用Postman)而不是我的RESTful服务器上,但这里有两个重要部分:
复杂类(C#)
public class PutData
{
public string ind { get; set; }
public string str { get; set; }
}
PUT方法(C#)
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, UriTemplate = "/Tutorial",
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public void EditTutorial(Object json) //<- have also tried PutData and string
{
var jsonString = json.ToString();// this Object implementation is from another S.O. page
PutData data = JsonConvert.DeserializeObject<PutData>(jsonString);
int pid;
Int32.TryParse(data.ind, out pid);
lst[pid] = data.str;
}
JSON作为PUT发送(邮差)
{ "ind" : "0", "str" : "Dictionary" }
我的邮差设置
正文:原始JSON(application / json)
Content-Type:application / json
有什么想法吗?