key固定
dynamic objmatch = new ExpandoObject();
Dictionary<string, string> matchKV = new Dictionary<string, string>();
matchKV.Add("name", "jk");
matchKV.Add("age","25");
Dictionary<string, string> matchKV2 = new Dictionary<string, string>();
matchKV2.Add("realName", "zs");
matchKV2.Add("realAge", "9");
List<dynamic> matchList = new List<dynamic>();
matchList.Add(matchKV);
matchList.Add(matchKV2);
objmatch.match = matchList;
dynamic obj = new ExpandoObject();
obj.query = objmatch;
obj.page = 5;
string json = JsonConvert.SerializeObject(obj);
key不确定
dynamic obj = new ExpandoObject();
Dictionary<string, object> JsonProperties = new Dictionary<string, object>();
JsonProperties.Add("Name", "张三");
JsonProperties.Add("Sex", "男");
JsonProperties.Add("Age", 12);
List<dynamic> ParaArr = new List<dynamic>();
Dictionary<string, object> bookProperties = new Dictionary<string, object>();
bookProperties.Add("Name","语文");
bookProperties.Add("Prices",15);
ParaArr.Add(bookProperties);
JsonProperties.Add("课程", ParaArr);
obj = JsonProperties;
//obj.query = objmatch;
//obj.page = 5;
//string Name = "Name";
//string age = "age";
//obj[Name] = "111";
//obj[age] = 1;
//obj.Name
//obj = ParaArr;
string json = JsonConvert.SerializeObject(obj);
网友评论