javascript - 在 JavaScript 中将 JSON 对象转换为数组
问题描述
我从第三方 api 获取 JSON 对象。我正在尝试将其转换为对象数组。
key: {
id1: {key:value},
id2: {key:value},
...
}
至
arrayName: [
{key:id1, Key:value},
{key:id1, Key:value}]
如果完全可以理解,希望我的描述。任何帮助,将不胜感激
解决方案
这可能会有所帮助
const a = {key: {
id1: {key:"1"},
id2: {key:"2"}
}}
const res = Object.entries(a.key).map(([k,v]) => {return {key:k, Key: v.key}});
console.log(res); // your desired result
在这里查看演示
推荐阅读
- web - 从 3270 大型机屏幕调用网站自动从大型机传递数据
- php - 使用 ajax 调用的 php 脚本重定向到另一个页面
- c# - 如果 JSON.NET 中的值为 null 或空格,则防止序列化
- angular - 如何在Angular 5中初始化Material Design的mat-slide-toggle?
- php - 使用php脚本定位ip所在国家/地区的最佳网站是什么
- javascript - localStorage.getItem(...).key 不是函数
- oracle-apex-5.1 - Oracle APEX 图标列表
- rabbitmq - 如何在不使用事务的情况下使用 RabbitMQ 和 Spring AMQP 实现至少一次交付保证?
- ios - Swift 4 Dictionary [String : AnyObject] 按字母顺序按键排序
- ios - L2CAP 通道数据传输