如何快速轻松地将电子表格数据转换为 JSON?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19187085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:51:28  来源:igfitidea点击:

How can I quickly and easily convert spreadsheet data to JSON?

jsonspreadsheetxlsfile-conversion

提问by B. Clay Shannon

I want to convert spreadsheet data (such as from Excel/*.xls files or Open Office, etc.) to JSON files. What is the easiest way to accomplish this?

我想将电子表格数据(例如来自 Excel/*.xls 文件或 Open Office 等)转换为 JSON 文件。实现这一目标的最简单方法是什么?

回答by B. Clay Shannon

Assuming you really mean "easiest" and are not necessarily looking for a way to do this programmatically, you can do this:

假设您的意思是“最简单”并且不一定要寻找以编程方式执行此操作的方法,您可以这样做:

0) Add, if not already there, a row of "column Musicians" to the spreadsheet. That is, if you have data in columns such as:

0) 在电子表格中添加一行“音乐家列”(如果还没有)。也就是说,如果您的列中有数据,例如:

Rory Gallagher  Guitar
Gerry McAvoy    Bass
Rod de'Ath  Drums
Lou Martin  Keyboards
Donkey Kong Sioux   Self-Appointed Semi-official Stomper

...you might want to add "Musician" and "Instrument" in row 0 (you might have to insert a row there)

...您可能想在第 0 行添加“音乐家”和“乐器”(您可能需要在那里插入一行)

1) Save the file as a CSV file.

1) 将文件另存为 CSV 文件。

2) Copy the contents of the CSV file to the clipboard

2) 将 CSV 文件的内容复制到剪贴板

3) Go to http://www.convertcsv.com/csv-to-json.htm

3) 前往http://www.convertcsv.com/csv-to-json.htm

4) Verify that the "First row is column names" checkbox is checked

4)验证“第一行是列名”复选框被选中

5) Paste the CSV data into the content area

5) 将 CSV 数据粘贴到内容区域

6) Mash the "Convert CSV to JSON" button

6) 混搭“将 CSV 转换为 JSON”按钮

With the data shown above, you will now have:

有了上面显示的数据,您现在将拥有:

[
  {
    "MUSICIAN":"Rory Gallagher",
    "INSTRUMENT":"Guitar"
  },
  {
    "MUSICIAN":"Gerry McAvoy",
    "INSTRUMENT":"Bass"
  },
  {
    "MUSICIAN":"Rod D'Ath",
    "INSTRUMENT":"Drums"
  },
  {
    "MUSICIAN":"Lou Martin",
    "INSTRUMENT":"Keyboards"
  }
  {
    "MUSICIAN":"Donkey Kong Sioux",
    "INSTRUMENT":"Self-Appointed Semi-Official Stomper"
  }
]

With this simple/minimalistic data, it's probably not required, but with large sets of data, it can save you time and headache in the proverbial long run by checking this data for aberrations and abnormalcy.

使用这种简单/极简的数据,它可能不是必需的,但是对于大量数据,通过检查这些数据的畸变和异常情况,从众所周知的长期来看,它可以节省您的时间和头痛。

7) Go here: http://jsonlint.com/

7)去这里:http: //jsonlint.com/

8) Paste the JSON into the content area

8) 将 JSON 粘贴到内容区域

9) Mash the "Validate" button.

9) 捣碎“验证”按钮。

If the JSON is good, you will see a "Valid JSON" remark in the Results section below; if not, it will tell you where the problem[s] lie so that you can fix it/them.

如果 JSON 是好的,您将在下面的结果部分看到“有效的 JSON”注释;如果没有,它会告诉您问题出在哪里,以便您可以修复它/它们。