问题
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?
回答1:
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:
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)
1) Save the file as a CSV file.
2) Copy the contents of the CSV file to the clipboard
3) Go to http://www.convertcsv.com/csv-to-json.htm
4) Verify that the "First row is column names" checkbox is checked
5) Paste the CSV data into the content area
6) Mash the "Convert CSV to JSON" button
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/
8) Paste the JSON into the content area
9) Mash the "Validate" button.
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.
来源:https://stackoverflow.com/questions/19187085/how-can-i-quickly-and-easily-convert-spreadsheet-data-to-json