Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/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#_Asp.net Mvc_Json.net - Fatal编程技术网

C# 如何在C中解析JSON对象#

C# 如何在C中解析JSON对象#,c#,asp.net-mvc,json.net,C#,Asp.net Mvc,Json.net,我得到以下JSON数据 [{"id":"1","text":"System Admin","target":{"jQuery1710835279177001846":12},"checked":true,"state":"open"}, {"id":"2","text":"HRMS","target":{"jQuery1710835279177001846":34},"checked":false,"state":"open"}, {"id":"3","text":"SDBMS","target

我得到以下JSON数据

[{"id":"1","text":"System Admin","target":{"jQuery1710835279177001846":12},"checked":true,"state":"open"},
{"id":"2","text":"HRMS","target":{"jQuery1710835279177001846":34},"checked":false,"state":"open"},
{"id":"3","text":"SDBMS","target":{"jQuery1710835279177001846":42},"checked":false},
{"id":"8","text":"Admin","target":{"jQuery1710835279177001846":43},"checked":false},
{"id":"9","text":"My test Admin","target":{"jQuery1710835279177001846":44},"checked":false,"state":"open"},
{"id":"24","text":"ModuleName","target":{"jQuery1710835279177001846":46},"checked":false,"state":"open"}]
尝试使用强类型解析的

这是我的财产类

public class testclass
    {
        public string id { get; set; }
        public string text { get; set; }
        public string @checked { get; set; }
        public string state { get; set; }
        public target jQuery1710835279177001846 { get; set; }

    }
    public class testclass2
    {
        public List<testclass> testclass1 { get; set; }

    }

    public class target
    {
        public string jQuery1710835279177001846 { get; set; }
    }
我的控制器代码看起来像

 public void Test(string Name, object modeldata)
        {

            var obj = JsonConvert.DeserializeObject<testclass>(Name);

        }
公共无效测试(字符串名称、对象模型数据)
{
var obj=JsonConvert.DeserializeObject(名称);
}

你知道如何在C#

中解决这个问题吗?你有TestClass数组。所以应该是这样

var model= JsonConvert.DeserializeObject<List<testclass>>(Name);

Json字符串中似乎包含序列化数组对象,因为它包含
[]
。这意味着您有一个Json字符串,它是在数组对象序列化之后形成的。所以您需要反序列化为数组对象,所以请尝试以下操作

var obj = JsonConvert.DeserializeObject<List<testclass>>(jsonString);
var obj=JsonConvert.DeserializeObject(jsonString);

您的json对象如下所示

{
      "id":"1",
      "text":"System Admin",
      "target":{
         "jQuery1710835279177001846":12
      },
      "checked":true,
      "state":"open"
}
我想应该是这样的

{
      "id":"1",
      "text":"System Admin",
      "jQuery1710835279177001846":12,
      "checked":true,
      "state":"open"
}

我想从视图到服务器端获取数据
{
      "id":"1",
      "text":"System Admin",
      "target":{
         "jQuery1710835279177001846":12
      },
      "checked":true,
      "state":"open"
}
{
      "id":"1",
      "text":"System Admin",
      "jQuery1710835279177001846":12,
      "checked":true,
      "state":"open"
}