Immutable Js:如何反序列化一个复杂的 JS 对象
Immutablejs: How to deserialise a complex JS object
如果我从服务器接收到的数据 JSON 看起来像这样:
{
"f223dc3c-946f-4da3-8e77-e8c1fe4d241b": {
"name": "Dave",
"age": 16,
"jobs": [{
"description": "Sweep the floor",
"difficulty": 4
},{
"description": "Iron the washing",
"difficulty": 6
}]
},
"84af889a-8fc9-499b-a6ea-97e7a483130c": {
...
}
}
是否需要遍历所有的jobs
并将它们转换为Map
,然后将每个对象的jobs
转换为一个List
,然后整个事情进入 Map
?
或者 ImmutableJS 是否以递归方式为我完成这一切?
Immutable.fromJS()
正是为此而设计的。
如果我从服务器接收到的数据 JSON 看起来像这样:
{
"f223dc3c-946f-4da3-8e77-e8c1fe4d241b": {
"name": "Dave",
"age": 16,
"jobs": [{
"description": "Sweep the floor",
"difficulty": 4
},{
"description": "Iron the washing",
"difficulty": 6
}]
},
"84af889a-8fc9-499b-a6ea-97e7a483130c": {
...
}
}
是否需要遍历所有的jobs
并将它们转换为Map
,然后将每个对象的jobs
转换为一个List
,然后整个事情进入 Map
?
或者 ImmutableJS 是否以递归方式为我完成这一切?
Immutable.fromJS()
正是为此而设计的。