如何从json中提取所有键和值?使用 JavaScript

use*_*195 -1 javascript javascript-objects

我有这样的json。

{
  "a": 99,
  "b": "this, is, string",
  "c": "hi:"
}
Run Code Online (Sandbox Code Playgroud)

我想将所有键和值提取到这样的数组中。 在此输入图像描述

split(',')不起作用,,因为"b": "this, is, string",. 即使我也无法拆分使用,:因为存在:hi:,.

你能给我一些建议吗?

jab*_*baa 5

您可以Object.entries使用.flat

const fixedJson = `{
  "a": 99,
  "b": "this, is, string",
  "c": "hi:"
}`;

const obj = JSON.parse(fixedJson);

const result = Object.entries(obj).flat();

console.log(result);
Run Code Online (Sandbox Code Playgroud)