Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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# 在C中从JSON响应中删除多个斜杠时获取异常#_C#_Json_Xamarin.android - Fatal编程技术网

C# 在C中从JSON响应中删除多个斜杠时获取异常#

C# 在C中从JSON响应中删除多个斜杠时获取异常#,c#,json,xamarin.android,C#,Json,Xamarin.android,这是我的回答 {\"eventResponseList\":[{\"Event_Id\":\"E008\",\"Status_Code\":\"03\",\"Event_time \":\"\\\/Date(1417001099677)\\\/\"},{\"Event_Id\":\"E002\",\"Status_Code\":\"03\",\"Event_time\":\"\\\/Date(1417001099677)\\\/\"}]} 我正在使用这段代码来反序列化响应,但遇到异常

这是我的回答

{\"eventResponseList\":[{\"Event_Id\":\"E008\",\"Status_Code\":\"03\",\"Event_time     \":\"\\\/Date(1417001099677)\\\/\"},{\"Event_Id\":\"E002\",\"Status_Code\":\"03\",\"Event_time\":\"\\\/Date(1417001099677)\\\/\"}]}
我正在使用这段代码来反序列化响应,但遇到异常

 if (response.StatusCode == System.Net.HttpStatusCode.OK)
 {
   string sanitizedResponseContent = Regex.Replace(response.Content, @"\p{C}+", String.Empty);
   retunResponse = JsonConvert.DeserializeObject<RootObjectEventResponseList>(sanitizedResponseContent);
 }
但每次我在去掉斜线后得到这个

"\"{\"eventResponseList\":[{\"Event_Id\":null,\"Status_Code\":\"02\",\"Event_time\":\"\\\\\\/Date(1417013952712)\\\\\\/\"}]}\""

尝试使用这种方法。不知道它是否对你有效。但值得一试

var escape = Regex.Escape(@"\sterte\sfsfs\sssss\ssss");
var replace = Regex.Replace(escape, "\\\\", "");

您的DTO可能与此类似:

public class EventResponseList
{
    public string Event_Id { get; set; }
    public string Status_Code { get; set; }
    public DateTime Event_time { get; set; }
}

public class RootObjectEventResponseList
{
    public List<EventResponseList> eventResponseList { get; set; }
}

你在哪里看到这些斜线?如果它在调试器中,那么它们不是字符串的一部分,调试器中的检查器只是在添加它们。会出现什么样的异常?消息是什么?我99%确定您正在查看调试器工件,并且误解了您所看到的内容。我在断点处得到了这个消息
public class EventResponseList
{
    public string Event_Id { get; set; }
    public string Status_Code { get; set; }
    public DateTime Event_time { get; set; }
}

public class RootObjectEventResponseList
{
    public List<EventResponseList> eventResponseList { get; set; }
}
var json = Regex.Replace(response.Content, @"Event_time[\s]+", "Event_time");