我在json数组中存储json对象并将其分配给另一个主json对象,但是当我打印主json对象的值时,它显示1.下面是代码。json对象显示值1
var jsonMainObject= {};
var jsonArray= [];
for(var j=0;j<cu.receivedData.length;j++) {
jsonMainObject["company"] = jsonArray.push(cu.receivedData[j].company);
}
console.log(jsonMainObject)
下面是输出
{ company: 1 }
但它应该显示阵列。当我打印jsonArray它显示对象的数组,但是当我控制jsonMainObject的输出时,它显示上面的输出。
您需要提供更多的代码/环境。 'cu.receivedData'变量是什么样的。那么'jsonArray'变量呢? – DesignerGuy
另外,JSON只是表示javascript对象的一种格式。所以,没有像“JSON对象”本身那样的东西。在javascript中有对象,而在JSON中表示的JavaScript对象(最终只是一个字符串)。 – DesignerGuy