如何添加另一个"条目“;转换为此JSON
How to add anther "entry" into this JSON?
我下载了一些JSON,如下所示。在开发人员控制台中,它看起来像是一个包含嵌套对象的对象,其中包含嵌套对象。。。
我想在数据中添加一个新的、空的"活动"(在前面)。我该怎么做?
插入
var blankCampaignData = {'title': '', 'description': '', 'path_to_logo': '', 'start_time': date, 'end_time' : date, 'paused': false};
进入
{
"campaigns": {
"1": {
"campaign_id": "1",
"title": "Nike Air 2015 campaign",
"description": null,
"path_to_logo": null,
"start_time": "09/11/2015 22:42:08",
"end_time": "09/03/2016 22:42:08",
"paused": "0",
"destinations": {
"1": {
"destination_id": "1",
"campaign_id": "1",
"url": "www.nike.com/nike_air",
"description": "Nike air destination",
"connections": {
"3": {
"connection_id": "3",
"destination_id": "1",
"tag_id": "0",
"country": "Scotland",
"county": "Yorkshire",
"town": "East Ham",
"post_code": "SE1 1AA",
"custom": "bus stop",
"description": "Connection number 3"
}
}
},
"2": {
"destination_id": "2",
"campaign_id": "1",
"url": "www.nike.com/nike_air/sub_campaign",
"description": "Nike air - free laces promotion destination",
"connections": {
"2": {
"connection_id": "2",
"destination_id": "2",
"tag_id": "0",
"country": "Engerland",
"county": "Devon",
"town": "East Ham",
"post_code": "SE1 1AA",
"custom": "bus stop",
"description": "Connection number 2"
},
"4": {
"connection_id": "4",
"destination_id": "2",
"tag_id": "0",
"country": "Engerland",
"county": "Yorkshire",
"town": "Felixswtowe",
"post_code": "RB3 9YR",
"custom": "police staticon",
"description": "Connection number 4"
},
"6": {
"connection_id": "6",
"destination_id": "2",
"tag_id": "0",
"country": "Scotland",
"county": "Essex",
"town": "York",
"post_code": "JD8 4LF",
"custom": "somewhere else",
"description": "Connection number 6"
},
"9": {
"connection_id": "9",
"destination_id": "2",
"tag_id": "0",
"country": "Scotland",
"county": "Cork",
"town": "York",
"post_code": "JD8 4LF",
"custom": "in the ladies' loo",
"description": "Connection number 9"
}
}
}
}
},
"2": {
"campaign_id": "2",
"title": "Nike football boots campaign",
"description": null,
"path_to_logo": null,
"start_time": "09/12/2015 22:42:08",
"end_time": "09/01/2016 22:42:08",
"paused": "0",
"destinations": {
"3": {
"destination_id": "3",
"campaign_id": "2",
"url": "www.nike.com/nike_football_boots/",
"description": "Nike footie boots destination",
"connections": {}
},
"4": {
"destination_id": "4",
"campaign_id": "2",
"url": "www.nike.com/nike_football_boots/sub_campaign",
"description": "Buy left boot, get right boot free destination",
"connections": {}
}
}
},
"3": {
"campaign_id": "3",
"title": "Nike general promotion campaign",
"description": null,
"path_to_logo": null,
"start_time": "09/12/2013 22:42:08",
"end_time": "09/08/2016 22:42:08",
"paused": "0",
"destinations": {
"5": {
"destination_id": "5",
"campaign_id": "3",
"url": "www.nike.com/general_promotion",
"description": "Nike general promotion destination",
"connections": {}
},
"6": {
"destination_id": "6",
"campaign_id": "3",
"url": "www.nike.com/general_promotion/discount_coupon",
"description": "20% off coupon destination",
"connections": {}
}
}
}
}
}
确定下一个活动id应该是什么:
var nextId = +Object.keys(obj.campaigns).sort().pop() + 1;
将空的市场活动添加到市场活动对象中。显然,您需要预先定义date
。
obj.campaigns[nextId] = {
'title': '',
'description': '',
'path_to_logo': '',
'start_time': date,
'end_time' : date,
'paused': false
}
相关文章:
- 如何在JavaScript中将字符串转换为函数引用
- 如何在Javascript中将JSon对象转换为数组
- 使用JS将数组转换为json对象
- 如何使用json将对象列表从java转换为javascript
- 偶尔结结巴巴地说“;堆叠的”;translate()上的转换(v4.0.0-alpha40)
- 为什么在单独的函数中应用时转换会闪烁/断断续续(D3)
- 在Javascript中转换对象数组
- 将数字转换为一定数量的硬币
- 将纯文本URL转换为可单击链接
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 如何使用js将SNAPSHOT内部版本号转换为3位数的整数
- 表达式引擎扩展开发-向呈现的条目添加自定义javascript
- 如何将TypeScript对象转换为普通对象
- 检测个位数整数时正在转换毫秒
- 从javascript到jquery的转换
- 如何在 Firefox 中查找特定的缓存条目并将它们转换为文件或 Blob 对象
- 如何添加另一个"条目“;转换为此JSON
- 如何使用Javascript将数组的值转换为每个条目中的不同键
- 要求的事情.主体在20个条目后自动将数组转换为对象
- 将值转换为json/object并更新条目