简体   繁体   English

如何将对象数组转换为单个JSON文档/对象

[英]How to convert an Array of objects single JSON Document/Object

I'm trying to convert an array objects to a JSON Document 我正在尝试将数组对象转换为JSON文档

My array is 我的数组是

var images = [{"id1":{"type":"image/png",data:blob}}, {...}, {..}  ...];

And I want to convert it into a Json Document containing all the elements of array 我想将其转换为包含数组所有元素的Json Document

ex: 例如:

var someOtherObject = {
"_id":"12345",
"name":"test",
"_attachments":{images[0],images[1]...}

the array size is dynamic, So i can't hardcode them as i did above. 数组大小是动态的,因此我无法像上面那样对它们进行硬编码。

Thanks 谢谢

If you _attachments is dynamic, it should be an array of objects inside your main object. 如果_attachments是动态的,则它应该是主对象内的对象数组。

var images = [{"id1":{"type":"image/png",data:blob}}, {...}, {..}  ...];

var someOtherObject = {
"_id":"12345",
"name":"test",
"_attachments":images

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM