日期:2014-05-17 浏览次数:20924 次
function ChangeDateFormat(cellval) { try { var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10)); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); return date.getFullYear() + "-" + month + "-" + currentDate; } catch (e) { return ""; } }
------解决方案--------------------
专程实体类或者实体类集合吗?给你个类
/// <summary>
/// Json工具类
/// </summary>
public static class JSONUtils
{
/// <summary>
/// 序列化数据为Json数据格式.
/// </summary>
/// <param name="value">被序列化的对象</param>
/// <returns></returns>
public static string ToJson(this object value)
{
Type type = value.GetType();
Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
json.NullValueHandling = NullValueHandling.Ignore;
json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
json.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
StringWriter sw = new StringWriter();
Newtonsoft.Json.JsonTextWriter writer = new JsonTextWriter(sw);
writer.Formatting = Formatting.None;
writer.QuoteChar = '"';
json.Serialize(writer, value);
string output = sw.ToString();
writer.Close();
sw.Close();
return output;
}
/// <summary>
/// 将Json数据转为对象
/// </summary>
/// <typeparam name="T">目标对象</typeparam>
/// <param name="jsonText">json数据字符串</param>
/// <returns></returns>
public static T FromJson<T>(this string jsonText)
{
Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
json.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
StringReader sr = new StringReader(jsonText);
Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
T result = (T)json.Deserialize(reader, typeof(T));
reader.Close();
return result;
}
}
//转换成json JSONUtils.ToJson(类);
//转换成实体类 JSONUtils.FromJson<类的名字>(json字符串)