Person person = JsonHelper.JsonToEntity<Person>(str); var customfields = JsonHelper.JsonToList<CustomFields>(str); List<Images> image = JsonHelper.JsonToList<Images>(str); c.Code = c.Code; string sql = "insert into dbo.A(UserID,BatchID,CityCode,CustomFields,Images,Time,LineName,Note,PO_Code,Pile,Version,Lat,Lon,Alt,Type,CFCode)values('" + person.UserID + "','" + person.BatchID + "','" + person.CityCode + "','" + person.CustomFields + "','" + person.Images + "','" + person.Time + "','" + person.LineName + "','" + person.Note + "','" + person.PO_Code + "','" + person.Pile + "'," + person.Version + "," + person.Lat + "," + person.Lon + "," + person.Alt + "," + person.Type + ",'" + customfields. + "')"; SqlConnection conn = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); string path2 = "E:/国省道采集数据"; path = Environment.CurrentDirectory; string pattern = "Command.txt"; string[] strFileName = Directory.GetFiles(path2, pattern); foreach (var item in strFileName) { File.Delete(item); } //var xuliehua = str; //StreamReader sr = new StreamReader(@"E:\国省道采集数据\Command.txt", Encoding.GetEncoding("gb2312")); //MessageBox.Show(sr.ToString()); } toolStripProgressBar1.Value = 0; MessageBox.Show("解压缩成功!"); } else { MessageBox.Show("警告:请选择要进行批量解压缩的文件!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { } } private void txtfiles2_TextChanged(object sender, EventArgs e) { } [DataContract] public class Person { public string UserID { get; set; } public string BatchID { get; set; } public string CityCode { get; set; } public List<CustomFields> CustomFields { get; set; } public List<Images> Images { get; set; } public string Time { get; set; } public string LineName { get; set; } public string Note { get; set; } public string PO_Code { get; set; } public string Pile { get; set; } public int Version { get; set; } public double Lat { get; set; } public double Lon { get; set; } public double Alt { get; set; } public int Type { get; set; } } [Serializable] public class CustomFields { [DataMember] public string Code { get; set; } [DataMember] public string Value { get; set; } } [Serializable] public class Images { public string Time { get; set; } public string FileName { get; set; } public double Lon { get; set; } public double Lat { get; set; } public double Alt { get; set; } } public class JsonHelper { public static List<T> JsonToList<T>(string jsonStr) { JavaScriptSerializer js = new JavaScriptSerializer(); //List<T> t = (List<T>) js.Deserialize(str, typeof(List<T>)); List<T> t = js.Deserialize<List<T>>(jsonStr); return t; } public static T JsonToEntity<T>(string jsonStr) { JavaScriptSerializer js = new JavaScriptSerializer(); T t = js.Deserialize<T>(jsonStr);//(T)js.Deserialize(str, typeof(T)); return t; } }
字符串为{"UserID":"huangshan1@78","BatchID":"1489281487936","CityCode":"341000","CustomFields":[{"Code":"GLDWMC","Value":"徽州交通局"},{"Code":"QLMC","Value":"杨村2号桥"},{"Code":"QLBH","Value":"K3001"},{"Code":"JCSJ","Value":""},{"Code":"QLCD","Value":"134"},{"Code":"SJHZ","Value":"1"},{"Code":"AKJF","Value":"2"},{"Code":"AJCHNXF","Value":"1"},{"Code":"B_ISDANGER","Value":"2"},{"Code":"KJZC","Value":"125"},{"Code":"DKZDKJ","Value":"25"},{"Code":"QMQK","Value":"8.5"},{"Code":"QMJK","Value":"7.4"},{"Code":"LXBM","Value":"S103341000"},{"Code":"LDXLH","Value":"001"}],"Images":[{"Time":"Mar 12, 2017 12:00:00 AM","FileName":"/storage/emulated/0/easyroad/collectionpo/1489282287821.jpeg","Lon":118.1775853,"Lat":29.97436336,"Alt":0.0}],"Time":"2017-03-12","LineName":"S103341000","Note":"","PO_Code":"T_ql","Pile":"5.092","Version":2,"Lat":29.97436336,"Lon":118.1775853,"Alt":0.0,"Type":4}
现在person的可以正常转化,但是CustomFields这个就无法反序列化然后
customfields也点不出来东西
三国纷争
交互式爱情
白板的微信
隔江千里
慕森王
慕的地10843
相关分类