IE 8中的json字符串给出了运行时错误Object属性或方法不受支持



/*问题描述-我使用json-stringify方法将javascript数组转换为json表示法中的字符串。然而,我在第行收到一条错误消息,"不支持Object属性或方法"hidden.value=JSON.stringfy(jsonObj);这应该起作用,因为在IE8中支持字符串。请通知

Full code below  */    
function getgridvalue() {
        var exportLicenseId;
        var bolGrossQuantity;
        var bolNetQuantity;
        var totalBolGrossQty =0 ;
        var totalBolNetQty =0;
        var jsonObj = []; //declare array
            var netQtyTextBoxValue = Number(document.getElementById("<%= txtNetQty.ClientID %>").value);
        var atLeastOneChecked = false;
        var gridview = document.getElementById("<%= ExporterGrid.ClientID %>"); //Grab a reference to the Grid
        for (i = 1; i < gridview.rows.length; i++) //Iterate through the rows
        {
            if (gridview.rows[i].cells[0].getElementsByTagName("input")[0] != null && gridview.rows[i].cells[0].getElementsByTagName("input")[0].type == "checkbox")
            {
                if (gridview.rows[i].cells[0].getElementsByTagName("input")[0].checked)
                {
                    atLeastOneChecked = true;
                    exportLicenseId = gridview.rows[i].cells[8].getElementsByTagName("input")[0].value;
                    bolNetQuantity = gridview.rows[i].cells[5].getElementsByTagName("input")[0].value;
                    if (bolNetQuantity == "") {
                        alert('<%= NetQuantityMandatory %>');
                        return false;
                        }
                    if (!isNumber(bolNetQuantity)) {
                        alert('<%= NetQuantityNumber %>');
                        return false;
                    }
                    totalBolNetQty += Number(bolNetQuantity);
                    jsonObj.push({ ExportLicenseId: Number(exportLicenseId),  BolNetQuantity: Number(bolNetQuantity) });
                }
            }
        }
if (gridview.rows.length > 2 && !atLeastOneChecked)
{
    alert('<%= SelectMsg %>');
                        return false;
                    }

if (totalBolNetQty != 0 && netQtyTextBoxValue != totalBolNetQty)
            {
                alert('<%= NetQuantitySum %>');
                return false;
            }
        var hidden = document.getElementById('HTMLHiddenField');
//        if (!this.JSON) {
//            this.JSON = {};
//        }
        var JSON = JSON || {};
        if (hidden != null) {
            hidden.value = JSON.stringify(jsonObj);
        }
    }

使用F12开发工具检查浏览器模式。JSON对象存在,但在IE7模式下没有方法。使用json2库作为后备。

  • json2.js

最新更新