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:,.
你能给我一些建议吗?
您可以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)