我将以下数据作为输出:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
{
"Table1": [
{
"ID": "127",
"Name": "Test"
},
{
"ID": "128",
"Name": "Test2"
},
{
"ID": "129",
"Name": "Test3"
}
]
}
</string>
我尝试使用以下代码将我的数据集结果转换为Json结果:
JsonConvert.SerializeObject(dataset, Formatting.Indented);
这是我的物业代码:
public string GetiGPClientMaster()
{
using (var context = new TestData())
{
try
{
DataSet dataset = new DataSet();
IQueryable<ClientMaster> result = PersistSvr<ClientMaster>.GetAll(context).Where(i => i.Status == true);
List<WCFSource> listClient = result.Select(b => new WCFSource() { ID = b.ClientID, Name = b.ClientName }).ToList();
DataTable dt = ConvertToDatatablePayGroup(listClient);
dataset.Tables.Add(dt);
return JsonConvert.SerializeObject(dataset, Formatting.Indented);
}
catch (Exception ex)
{
return string.Empty;
}`
}
}