将json HashMap加载到javascript对象中

时间:2018-03-08 07:56:22

标签: javascript json dictionary hashmap lodash

您好我从我的Java应用程序中发送了HashMap<String, List<MyObject>>,如下所示:

{
    "316N": [
        {
            "userCreate": null,
            "dateCreate": null,
            "userMaj": null,
            "dateMaj": null,
            "archive": false,
            "nomComposant": "cob",
            "versionComposant": 2,
            "checksumSrcComposant": "1235",
            "checksumBinComposant": "1235"
        }
    ]
}

有没有办法简单地将这个json对象解析为Map或sthg来自一个我不知道的酷javascript lib(在lodash中找不到)。

1 个答案:

答案 0 :(得分:3)

只需使用Map构造函数获取Object.entries

的输出
new Map( Object.entries( obj ) )

<强>演示

&#13;
&#13;
var obj = {
    "316N": [
        {
            "userCreate": null,
            "dateCreate": null,
            "userMaj": null,
            "dateMaj": null,
            "archive": false,
            "nomComposant": "cob",
            "versionComposant": 2,
            "checksumSrcComposant": "1235",
            "checksumBinComposant": "1235"
        }
    ]
};
var output =  new Map( Object.entries( obj ) );

var mapIter = output.entries();

console.log(mapIter.next().value);
&#13;
&#13;
&#13;