我有几个返回不同通用列表的方法.
在.net中存在任何类静态方法或将任何列表转换为数据表的任何东西?我唯一可以想象的是使用Reflection来做到这一点.
如果我有这个:
List<Whatever> whatever = new List<Whatever>();
Run Code Online (Sandbox Code Playgroud)
(下一个代码当然不起作用,但我想有可能:
DataTable dt = (DataTable) whatever;
Run Code Online (Sandbox Code Playgroud) 有没有一种简单的方法来填充我的C#对象与通过AJAX传递的JSON对象?
//这是使用JSON.stringify从页面传递给C#WEBMETHOD的JSON对象
{
"user": {
"name": "asdf",
"teamname": "b",
"email": "c",
"players": ["1", "2"]
}
}
Run Code Online (Sandbox Code Playgroud)
// C#WebMetod接收JSON对象
[WebMethod]
public static void SaveTeam(Object user)
{
}
Run Code Online (Sandbox Code Playgroud)
// C#类,表示传入WebMethod的JSON Object的对象结构
public class User
{
public string name { get; set; }
public string teamname { get; set; }
public string email { get; set; }
public Array players { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我想一般扁平一些json所以我可以转换为数据表并使用c#绑定到数据网格
什么是最好的办法,记住我不知道我要下多少级别?
例如
{
"appointmentid": 4,
"policyid": 1,
"guid": "00000000-0000-0000-0000-000000000000",
"number": "1234567890",
"ampm": "false",
"date": "2015-09-08T00:00:00",
"vehicle": {
"id": 1,
"guid": "00000000-0000-0000-0000-000000000000",
"make": null,
"model": null
},
"installer": {
"installerid": "1",
"name": "Installer 1",
"contact": "qwerty",
"qascore": "0",
"address1": "qwerty",
"address2": "qwerty",
"address3": null,
"address4": null,
"city": "qwertyu",
"county": "qwertyu",
"postcode": "asdfghj",
"country": "GB",
"email": "asdfghj",
"web": "asdfghjk",
"archived": false
},
"installations": [
{
"installationid": 6,
"installationstatus": {
"installationstatusid": 4,
"installationstatus": "FAIL"
},
"isactive": true
},
{
"installationid": 7,
"installationstatus": … 有谁知道如何从asp.net将json字符串转换为DataTable?我开始了解Deserialize,它需要类,我只想要返回数据表.谁能告诉我如何将其转换为数据表?
我正在使用Web服务创建一个C#应用程序.在我的Web服务中,我正在使用JSONString数据.但我无法将此字符串转换为DataSet.
我JSONString是:
{
"Table": [
{
"DisplayVoucherNumber": "A101239Z",
"ActualDate": "08/07/2013",
"AccountName": "shyamal",
"Pcs": "50",
"Weight": "500.000"
}
],
"Table1": [
{
"DisplayVoucherNumber": "R101249B",
"ActualDate": "11/07/2013",
"AccountName": "vipul",
"NetWeight": "90.000",
"Weight": "80.000",
"Difference": "10.000"
},
{
"DisplayVoucherNumber": "R101249B",
"ActualDate": "11/07/2013",
"AccountName": "vipul",
"NetWeight": "500.000",
"Weight": "100.000",
"Difference": "400.000"
}
]
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将JSON文本序列化为DataTable,如下所示.
List<Dictionary<string, string>> list =
JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(jsonText);
DataTable dTable;
dTable = (from p in list select p).CopyToDataTable();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.我如何解决它?
错误:
Cannot deserialize JSON object into type
'System.Collections.Generic.List`1[System.Collections.Generic.Dictionary`2
[System.String,System.String]]'.
Run Code Online (Sandbox Code Playgroud)