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

标签 angularjs json node.js mean-stack meanjs

嗨,当我上传应保存到 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/

相关文章:

node.js - 读取 CSV 文件的最后一行并提取一个值

javascript - 我的模板没有被解析

javascript - Angular - 我的 $resource .query 值的字符作为单独的参数发送,为什么?

python - 将 json.dump 移植到 StringIO 代码到 python 3

json - 如何从嵌套文档数组中删除/更新

javascript - 根据键值显示 JSON 文件中的值

javascript - 带过滤器的 AngularJS ng-repeat 第二次返回空数组

javascript - 如何使用 Angular 的 ng-style 从 JSON 文件获取数据

javascript - 在Terminal中通过node JS输入

javascript - 对 Javascript 闭包案例感到困惑