1.excel转json
这个可以参见前辈python的方式:
https://github.com/gdgoldlion/ExcelAndJSON
不过这个需要装python和xlrd,装xlrd的时候需要用命令:
python setup.py install
在win32上用批处理这样转换excel到json:
python %~dp0../src/excel_and_json.py singlebook -o ./ -i test.xlsx
2.js里读取json
fs.readFile = function (file) {
var path = this.fullPath(file);
return jsb.fileUtils.getStringFromFile(path);
}
fs.readJson = function (file) {
var data = this.readFile(file);
var ret;
try {
ret = JSON.parse(data);
} catch (e) {
console.log('read json ', file, ' error.');
}
return ret;
}