当尝试对包含对象数组的对象进行字符串化时,当我看到我有值时,我得到一个空数组。
filterDto: {
Expressions: []
},
/* Using a tempArray to see if its an object issue of my filterDto.Expressions */
fnBuildFilterValues: function() {
var invoiceObj = this;
var tempArray = new Array();
$("#tblExpressions tr").each(function() {
var doWeAddRow = false;
var filterObject = {
"Field": {},
"Condition": {},
"DataValue": {}
};
$(this).find(":input").each(function() {
if ( $(this).attr('name') === 'ddlFieldExp' ) {
filterObject.Field = $(this).val();
}
if ( $(this).attr('name') === 'ddlConditionExp' ) {
filterObject.Condition = $(this).val();
}
if ( $(this).attr('name') === 'tbDataExp' ) {
filterObject.DataValue = $(this).val();
}
}); /* Inner loop */
tempArray.push(filterObject);
}); /* Outer loop */
invoiceObj.filterDto.Expressions = tempArray;
},
我想要的是使用类似的东西:
var objToString = {};
objToString = JSON.stringify(invoiceObj.filterDto)
我尝试使用 = {} 作为补救措施,但当我的数组被填充时,我仍然最终得到 ObjToString 为空。它是这样显示的: {"Expressions":[]}
如果我在右侧部分的 VS 中进行快速观察,JSON.Stringify 我得到这个:
JSON.stringify(invoiceObj.filterDto)
"{"Expressions":[{"Field":"6","Condition":"0","DataValue":"2"}]}" String
但是为什么 ObjToString 显示一个空的结果呢?