JS JSON对象相关
1、多对象合并
将2个或2个以上对象(object{....})中的属性进行合并,即最后合并为一个object{.....}
解决办法:Object.assign 方法
var form = {name: 'liming', sex: '男'}; var obj = {class: '一班', age: 15}; console.log('before', form); Object.assign(form, obj); console.log('after', form);
2、C# JSON对象遍历 , 遍历Json 形成键值对
string test_json = "{\"name\":\"tom\",\"nickname\":\"tony\",\"sex\":\"male\",\"age\":20,\"email\":\"123@123.com\"}"; var o = JObject.Parse(yourJsonString); foreach (JToken child in o.Children()) {
var property1 = child as JProperty;
MessageBox.Show(property1.Name + ":" + property1.Value); }
斩后知