Exemple #1
0
        public static List <Dictionary <object, object> > ListToDataTable(DataTable dt)
        {
            try
            {
                var serializer = new JsonStringSerializer();
                var dict       = new List <Dictionary <object, object> >();
                foreach (DataRow row in dt.Rows)
                {
                    var dic = new Dictionary <object, object>();

                    foreach (DataColumn col in dt.Columns)
                    {
                        var value = row[col];
                        if (value == DBNull.Value)
                        {
                            value = "";
                        }
                        else if (value.GetType() == typeof(byte[]))
                        {
                            value = serializer.DeserializeFromString <Dictionary <string, dynamic> >(Encoding.UTF8.GetString(value as byte[]));
                        }

                        dic[col.ColumnName] = value;
                    }
                    dict.Add(dic);
                }

                return(dict);
            }
            catch (Exception ex)
            {
                LogWriter.Error(ex.ToString());
                return(null);
            }
        }
Exemple #2
0
        public static T JsonDeserialize <T>(string str)
        {
            var ser = new JsonStringSerializer();

            return(ser.DeserializeFromString <T>(str));
        }