1
I wanted to know how to create a JSON and then add elements dynamically.
The initial JSON needs to be like this:
{
id: Lime.Guid(),
type: "application/vnd.lime.collection+json",
to: "[email protected]",
content: {
itemType: "application/vnd.lime.document-select+json",
items: [ ]
}
}
So I need to go adding elements in Items
dynamically, based on an array I have.
Each item will be of the form:
{
header: {
type: "application/vnd.lime.media-link+json",
value: {
title: "Title",
text: "This is a first item",
type: "image/jpeg",
uri: "http://www.isharearena.com/wp-content/uploads/2012/12/wallpaper-281049.jpg"
}
}
}
I create it as follows in my code:
messageCarousel = '{ ' +
'id: Lime.Guid(), ' +
'type: "application/vnd.lime.collection+json",' +
'to: "[email protected]",' +
'content: { ' +
'itemType: "application/vnd.lime.document-select+json", ' +
'items: [ ] '+
'}' ;
And then I add the Items
:
var obj = JSON.parse(messageCarousel);
messageCarousel[items].push('{ header: ' +
' { type: "application/vnd.lime.media-link+json", ' +
'value: { ' +
'title: Name, ' +
'type: "image/jpeg", ' +
'uri: Uri }}' );
messageCarousel = JSON.stringify(obj);
Can someone tell me what’s wrong and how I should do it in the best way?
Thank you! It worked :3
– Bruno Camarda