using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE))
{
    con.Open();
    using (SQLiteCommand cmd = new SQLiteCommand())
    {
        cmd.Connection = con;
        cmd.CommandText = string.Format("select * from test ");
        int rows = cmd.ExecuteNonQuery();
        SQLiteDataAdapter oraDA = new SQLiteDataAdapter(cmd);
        DataSet ds = new DataSet();
        oraDA.Fill(ds);
        DataTable table = ds.Tables[0];
        var iso = new IsoDateTimeConverter();
        iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        string jsontable = JsonConvert.SerializeObject(table, iso);
        
    }
}

table是查询数据库后得到的数据,数据含有Date类型数据,经过如下<序列化+日期转化>处理,

        var iso = new IsoDateTimeConverter();
        iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        string jsontable = JsonConvert.SerializeObject(table, iso);

得到的json字符串jsontable 

 posted on 2016-12-15 15:13  布鲁布鲁sky  阅读(351)  评论(0编辑  收藏  举报