当前位置: 编程技术>.net/c#/asp.net
C#实体类转换成Json字符串的实现代码
来源: 互联网 发布时间:2014-08-30
本文导语: 本节内容: C#转换实体类为Json字符串 例子: 代码示例: ///实体类 namespaceDataInterface.Model { publicclassMetercs { publicstringMname{get;set;} publicstringTid{get;set;} publicstringTname{get;set;} publicstringTzdxh{get;set;} } publicclassMetercsList { // www...
本节内容:
C#转换实体类为Json字符串
例子:
代码示例:
///实体类
namespaceDataInterface.Model
{
publicclassMetercs
{
publicstringMname{get;set;}
publicstringTid{get;set;}
publicstringTname{get;set;}
publicstringTzdxh{get;set;}
}
publicclassMetercsList
{ // www.
publicListgetMetercs{get;set;}
}
}
///转换操作,转换成json字符串
ListReterminals=newList();
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);
namespaceDataInterface.Model
{
publicclassMetercs
{
publicstringMname{get;set;}
publicstringTid{get;set;}
publicstringTname{get;set;}
publicstringTzdxh{get;set;}
}
publicclassMetercsList
{ // www.
publicListgetMetercs{get;set;}
}
}
///转换操作,转换成json字符串
ListReterminals=newList();
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);