javascript - JSON.stringify not working with nested array in javascript
问题描述
I am trying to JSON.stringify(docArray)
which contains a nested array in the object that is not being stringified.
console.log(docArray); - returns the information below
(3) [{…}, {…}, {…}]
0:
docName: "name"
refDoc: Array(3)
0: "doc1"
1: "doc2"
2: "doc3"
length: 3
__proto__: Array(0)
__proto__: Object
When I stringify the object I receive the following :
console.log(JSON.stringfy(docArray));
[{"docName:"name","refDoc":[]},
Javascript to create the docArray
:
docArray = [];
for(let i = 0; i < data.length; i++){
let docElement = {
"docName": data[i].getAttribute("Title),
"refDoc": getDoc(data[i].getAttribute("Title"))
}
};
docArray.push(docElement);
...
console.log(docArray);
console.log(JSON.stringify(docArray));
getDocs
function Javascript
function getDoc(document){
var refDocs = [];
$SP().list("listName").get({
fields:"Title,Parent",
where:'Title ="'+document+'"',
}, function(data){
for(let i = 0; i < data.length; i++){
refdocs.push(data[i].getAttribute("Parent"));
}
});
return refdocs;
}
I do have a similar project that creates an array in the same fashion though that array does not have a problem being stringified. I have attached pictures below for the console.log outputs of that array.
Any help would be greatly appreciated, thank you!
解决方案
推荐阅读
- c# - Environment dependent controller with [Authorize]
- c# - 保存二进制文件的一部分
- sml - tycon 不匹配的问题
- python - 如何在 Django Rest Framework 中显示我的 M2M 模型
- python - 如何在 Hugo 中构建静态 html 页面并定义布局模板来格式化页面?
- pointers - Odd behavior of fortran strings in a derived type after accessing the type by a pointer
- python - 如何为多标签分类器/一对休息分类器腌制 sklearn 管道?
- javascript - 无法通过 reactjs 中的 html 表单进行后调用和发送文件
- node.js - 为什么 toString() 可以在参数上调用但不能直接调用
- html - 在响应式设计中将两行文本包裹在一起