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

 JSON相关

posted @ 2019-01-24 11:12  深海地平线  阅读(216)  评论(0编辑  收藏  举报