Background :
I need to get the image from path from below json file :
{
"path" : " shape\/",
"info" : {
"author" : ""
},
"name" : "shape",
"layers" : [
{
"height" : 612,
"layers" : [
{
"name" : "bg_rectangle_1"
},
{
"height" : 475,
"layers" : [
{
"src" : "http://sitename.com/images/oneheart.png",
"name" : "mask_image_1"
},
{
"name" : "useradd_ellipse1"
}
],
"name" : "user_image_1"
}
],
"name" : "loveshape_17"
}
]
}
I successfully did it with below code :
var maskedImageUrla = "";
$.getJSON('test.json', function(json) {
for (let layer of json.layers) {
if (layer.layers && layer.layers.length > 0) {
for (let temp of layer.layers) {
if (temp.src) maskedImageUrla = temp.src;
else if (temp.layers) {
for (let tl of temp.layers)
if (tl.src) maskedImageUrla = tl.src;
}
}
}
}
Requirement :
In above json file if src is like this : "src" : "oneheart.png" [instead of full path] , than how to get the image ? becasue image exist in this path : http://sitename.com/images/oneheart.png
Here is Full script & json file
/and append the url if it is not found