Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.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_List_Object - Fatal编程技术网

C# 如何在C上从json读取数据#

C# 如何在C上从json读取数据#,c#,json,list,object,C#,Json,List,Object,我将以下json对象传递给我的c#服务器 我创建了一个这样的类 public class Person { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } 当我这么做的时候 public static string addRecord(string details) { Person tempReco

我将以下json对象传递给我的c#服务器

我创建了一个这样的类

public class Person
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

}
当我这么做的时候

public static string addRecord(string details)
{
    Person tempRecord = JsonConvert.DeserializeObject<Person>(details);
    string tempFN = tempRecord.FirstName;
    return tempFN;
}

您的JSON包含三个
Person
s的集合,但您正在尝试将JSON反序列化,就像它是一个
Person
一样

Person tempRecord = JsonConvert.DeserializeObject<Person>(details);
    var jsonD = Ext.encode(Ext.pluck(this.myGridStore.data.items, 'data'));
    Ext.Ajax.request({
        scope: this,
        method: 'POST',
        url: 'myApp/AddRecord',
        headers: { 'Content-Type': 'application/json' },
        dataType: 'json',
        jsonData: jsonD,
        success: function (response) {
        },
        failure: function (response) {
        }
    });
Person tempRecord = JsonConvert.DeserializeObject<Person>(details);
var tempRecords = JsonConvert.DeserializeObject<List<Person>>(details);