1. 程式人生 > >Newtonsoft.Json.Linq對象讀取DataSet數據

Newtonsoft.Json.Linq對象讀取DataSet數據

sof json bject 數據 bsp copy convert .json tostring

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();
}

Newtonsoft.Json.Linq對象讀取DataSet數據