asp.net DataTable和Dataset序列化成Json格式(2)
}
}
}
调用的话:Dictionary<string, object> dt = Resolve.DataRowFromJSON(requestbuffer, context);
DatasetToJson:
public class DataSetConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return typeof(DataSet).IsAssignableFrom(objectType);
}
public override void WriteJson(JsonWriter writer, object value)
{
DataSet ds = (DataSet)value;
writer.WriteStartObject();
foreach (DataTable dt in ds.Tables)
{
writer.WritePropertyName(dt.TableName);
writer.WriteStartArray();
foreach (DataRow dr in dt.Rows)
{
writer.WriteStartObject();
foreach (DataColumn dc in dt.Columns)
{
writer.WritePropertyName(dc.ColumnName);
writer.WriteValue(dr[dc].ToString());
}
writer.WriteEndObject();
}
writer.WriteEndArray();
}
writer.WriteEndObject();
}
}
调用的话:JavaScriptConvert.SerializeObject(GetTestDataSet(), new DataSetConverter());
DataTableToJson2:
public class DataTableConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value)
相关新闻>>
- 发表评论
-
- 最新评论 更多>>