Newtonsoft.Json.Linq对象读取DataSet数据

Newtonsoft.Json.Linq对象读取DataSet数据:

private void button4_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable("t");
            dt.Columns.Add("a");
            dt.Columns.Add("b");
            dt.Rows.Add("1", "11");
            dt.Rows.Add("2", "22");

            DataSet ds = new DataSet();
            ds.Tables.Add(dt);

            dt = dt.Copy();
            dt.TableName = "t2";
            ds.Tables.Add(dt);
            string str = Newtonsoft.Json.JsonConvert.SerializeObject(ds);

            object obb = Newtonsoft.Json.JsonConvert.DeserializeObject(str);

            //string ss= obb["a"];
            JObject ob = (JObject)(obb);
            JArray ss = (JArray) ob["t"];
            JObject jo = (JObject)ss[0];
            string mm = jo["a"].ToString();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict["a"] = "111";
            dict["b"] = "dsf";
            dict["c"] = "dssssf";

            string str = Newtonsoft.Json.JsonConvert.SerializeObject(dict);

            object obb = Newtonsoft.Json.JsonConvert.DeserializeObject(str);
         
            //string ss= obb["a"];
            JObject ob =  ( JObject)(obb);
            string mm = ob["a"].ToString();
        }

posted @ 2018-11-04 23:05  81  阅读(598)  评论(0编辑  收藏  举报