Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
C# 如果Json变量包含空格或WCF中的任何特殊字符,如何获取Json值_C#_Json_Wcf - Fatal编程技术网

C# 如果Json变量包含空格或WCF中的任何特殊字符,如何获取Json值

C# 如果Json变量包含空格或WCF中的任何特殊字符,如何获取Json值,c#,json,wcf,C#,Json,Wcf,json 我的webMethod如下所示 class Model{ public string id { get; set; } public string date { get; set; } public string message_id { get; set; } public string ts { get; set; } public string ts_event { get; set; } } 执

json

我的webMethod如下所示

class Model{

        public string id { get; set; }
        public string date { get; set; }
        public string message_id { get; set; }
        public string ts { get; set; }
        public string ts_event { get; set; }
}
执行此操作时,我得到model.message_id的空值,因此我必须重构代码以

public response Post(Model model)
{
  string message_Id= model.message_id;
}

我的目标是在web方法中获取json的值(消息id)。如果是WCF,则使用如下DataMember属性存储在后端

class Model{

        public string id { get; set; }
        public string date { get; set; }

        [JsonProperty("message-id")]   //I have use newtonsoft.json 
        public string message_id { get; set; }
        public string ts { get; set; }
        public string ts_event { get; set; }
}

这确实对我有用
[JsonProperty(“message id”)]
[JsonProperty(“message id”)]
对我有用
JsonConvert.DeserializeObject
。这里的工作代码。@SOWMYADHARGOURSHETTY我正在尝试实现webhook。我看到了您使用反序列化对象的示例代码,但我希望将json值自动绑定到我的模型类,并将其作为参数传递给我的webMethod。感谢大家的快速反应和指导。
class Model{

        public string id { get; set; }
        public string date { get; set; }

        [JsonProperty("message-id")]   //I have use newtonsoft.json 
        public string message_id { get; set; }
        public string ts { get; set; }
        public string ts_event { get; set; }
}
[DataMember(Name = "message-id")]  
public string message_id { get; set; }