chatgpt帮我写代码-将文本中两列信息转json

提问:将这两列数据转为json 左侧是key右侧是value , key value 都是string 数据格式 1000000025 10000001 1000000024 10000002

下面是chatgpt的回答 To convert the two columns of data into a JSON object with keys and values as strings, you can use the following code in JavaScript: 代码 const data = 1000000025 10000001 1000000024 10000002;

const json = data.split(’\n’).reduce((acc, line) => { const [key, value] = line.split(’\t’); acc[key] = value; return acc; }, {});

console.log(json);

{ “1000000025”: “10000001”, “1000000024”: “10000002” }

本文链接:参与评论 »

--EOF--

提醒:本文最后更新于 525 天前,文中所描述的信息可能已发生改变,请谨慎使用。

Comments