using system;
using system.collections.generic;
using system.text;
using system.data;
using system.reflection;
using system.collections;
using system.data.common;
namespace dotnet.utilities
}return sb.tostring();
}/// /// 格式化字元型、日期型、布林型
///
private static string stringformat(string str, type type)
else if (type == typeof(datetime))
else if (type == typeof(bool))
else if (type != typeof(string) && string.isnullorempty(str))
return str;
}#endregion
#region list轉換成json
/// /// list轉換成json
///
public static string listtojson(ilistlist)
/// /// list轉換成json
///
public static string listtojson(ilistlist, string jsonname)
}if (i < list.count - 1)}}
return json.tostring();
}#endregion
#region 物件轉換為json
/// /// 物件轉換為json
///
/// 物件
/// json字串
public static string tojson(object jsonobject)
else if (objectvalue is string)
else if (objectvalue is ienumerable)
else
jsonstring += "\"" + tojson(propertyinfo[i].name) + "\":" + value + ",";
}jsonstring.remove(jsonstring.length - 1, jsonstring.length);
return jsonstring + "}";
}#endregion
#region 物件集合轉換json
/// /// 物件集合轉換json
///
/// 集合物件
/// json字串
public static string tojson(ienumerable array)
jsonstring.remove(jsonstring.length - 1, jsonstring.length);
return jsonstring + "]";
}#endregion
#region 普通集合轉換json
/// /// 普通集合轉換json
///
/// 集合物件
/// json字串
public static string toarraystring(ienumerable array)
jsonstring.remove(jsonstring.length - 1, jsonstring.length);
return jsonstring + "]";
}#endregion
#region dataset轉換為json
/// /// dataset轉換為json
///
/// dataset物件
/// json字串
public static string tojson(dataset dataset)
jsonstring = jsonstring.trimend(',');
return jsonstring + "}";
}#endregion
#region datatable轉換為json
/// /// datatable轉換為json
///
/// datatable物件
/// json字串
public static string tojson(datatable dt)
else}}
jsonstring.remove(jsonstring.length - 1, 1);
return jsonstring.tostring();
}/// /// datatable轉換為json
///
public static string tojson(datatable dt, string jsonname)
}if (i < dt.rows.count - 1)}}
return json.tostring();
}#endregion
#region datareader轉換為json
/// /// datareader轉換為json
///
/// datareader物件
/// json字串
public static string tojson(dbdatareader datareader)
else}}
datareader.close();
jsonstring.remove(jsonstring.length - 1, 1);
return jsonstring.tostring();
}#endregion
}}
DateTime日期轉換幫助類
用於查詢的日期型別轉換幫助類 1 使用者在ui上選擇日期 2 系統計算出今天的起始時間 年月日 00 00 00 和今天的結束時間 年月日 23 59 59 3 系統根據根據該日期範圍到資料庫取出該日期範圍的資料。如下圖所示,查詢指定日期的航班及機票數量 1 使用者在ui上選擇 起始日期 和 結束日...
轉換Json格式幫助類
using system using system.collections.generic using system.text using system.reflection using system.data using system.collections namespace aimscommo...
C Json轉換時間格式
可以使用設定iso時間轉換格式,轉換所有時間型別為統一格式 isodatetimeconverter timeconverter newisodatetimeconverter 這裡使用自定義日期格式,如果不使用的話,預設是iso8601格式 yyyy mm dd hh mm ss timeconv...