C#将实体类转换成Json字符串

*实体类

namespaceDataInterface.Model
{
publicclassMetercs
{
publicstringMname{get;set;}
publicstringTid{get;set;}
publicstringTname{get;set;}
publicstringTzdxh{get;set;}
}
publicclassMetercsList
{
publicList<Metercs>getMetercs{get;set;}
}
}

*转换操作

List<Metercs>Reterminals=newList<Metercs>();
foreach(varretinmeters)
{
Reterminals.Add(newMetercs(){Mname=ret.Mname,Tid=ret.Tid,Tname=ret.Tname,Tzdxh=ret.Tzdxh});
}
MetercsListTerminallist=newMetercsList();
Terminallist.getMetercs=Reterminals;
reStr=newJavaScriptSerializer().Serialize(Terminallist);

你可能感兴趣的:(字符串,public,meters)