C# 如何在C上从json读取数据#
我将以下json对象传递给我的c#服务器 我创建了一个这样的类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
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);