【发布时间】:2018-05-14 03:46:48
【问题描述】:
尝试了几天来操纵一些 JSON 数据响应。如何从以下创建哈希图?
var jsonObject = JSON.parse(xhr.responseText); //response that parced
用于搜索"volvo, opel, honda。解析后,它会返回每个索引的用户,看起来像这样(jsonObject.length 在每个不同的搜索中都会发生变化):
[{user: 1, car: volvo, score:7, time: "some time"},{user: 2, car: volvo, score:8, time: "some time"},{user: 3, car: volvo, score:9, time: "some time"},{user: 3, car: opel, score:6, time: "some time"},{user: 3, car: honda, score:8, time: "some time"},{user: 4, car: volvo, score:6, time: "some time"},{user: 4, car: opel, score:7, time: "some time"},{user: 5, car: honda, score:8, time: "some time"}]
我希望输出是这样的:
[{1:[7]},{2:[8]},{3:[9,6,8]},{4:[6,7]},{5:[8]}]
【问题讨论】:
-
你的jsonObject的结构是什么?
-
“结构”是什么意思,上面我举了个例子,抱歉没看懂问题
标签: javascript arrays json loops hashmap