gpt4 book ai didi

angularjs - 将 JSON.STRINGIFY 转换为 json 数组长度不计算

转载 作者:太空宇宙 更新时间:2023-11-04 03:04:48 24 4
gpt4 key购买 nike

嗨,当我上传应保存到 mongodb(数据库)的 Excel 时,我有 Excel 上传功能。我已将 Excel 单元格值作为 json stringify,并将其转换为解析。现在我不知道如何获取 json 长度值。

here i have attached my code

    function to_json(workbook) {
debugger;
console.log(workbook);
var result = {};
workbook.SheetNames.forEach(function(sheetName) {
$scope.Sheetname=sheetName; // here sheet name is excel sheet name

MainSheetName=sheetName;
var roa = X.utils.sheet_to_json(workbook.Sheets[sheetName]);
if(roa.length > 0){
result[sheetName] = roa;
}
});
return result;

}




var HTMLOUT = document.getElementById('htmlout');
function to_html(workbook) {
HTMLOUT.innerHTML = "";
workbook.SheetNames.forEach(function(sheetName) {
var htmlstr = X.write(workbook, {sheet:sheetName, type:'binary', bookType:'html'});
HTMLOUT.innerHTML += htmlstr;
});
}

var tarea = document.getElementById('b64data');
function b64it() {
if(typeof console !== 'undefined') console.log("onload", new Date());
var wb = X.read(tarea.value, {type: 'base64',WTF:wtf_mode});
process_wb(wb);
}
window.b64it = b64it;

var OUT = document.getElementById('out');
var global_wb;
function process_wb(wb) {
global_wb = wb;
var output = "";
var output1 = "";
switch(get_radio_value("format")) {

case "json":
output = JSON.stringify(to_json(wb), 2, 2);

output1=JSON.parse(output);
break;
case "form":
output = to_formulae(wb);
break;
case "html": return to_html(wb);
default:
output = to_csv(wb);
}
if(OUT.innerText === undefined) OUT.textContent = output;


else OUT.innerText = output;
debugger;

$scope.MainInfo=output1; // this return whole data
console.log(output1);
$scope.jsondata=output1.Sheet1[0].length;// this returns undefined. Here sheet name is excel file sheetName it will taken from excel.
console.log($scope.jsondata);

my output is showing like this

{
"Sheet1": [
{
"Name": "xxx",
"Age": "22",
"Salary": "222222"
},
{
"Name": "yyy",
"Age": "23",
"Salary": "232323"
},
{
"Name": "zzz",
"Age": "23",
"Salary": "232323"
}
]
}

现在我想要 Sheet1 的长度,我怎样才能得到它。谁能告诉我

最佳答案

如果您要将输出分配给obj,则获取Sheet1的长度就像obj.Sheet1.length一样简单

关于angularjs - 将 JSON.STRINGIFY 转换为 json 数组长度不计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44127846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com