0

I need search the assets types in a json but mapping I have a block key that is different in all blocks. I set a variable that cointains this values but when I want to use do not retrive the things after this block key. This is the code

for (var i = 0; i < jsonResponse.items.length; i++) {
  var email = jsonResponse.items[i];
  var emailName = email.name;
  var block = jsonResponse.items[i].views.html.slots.banner.blocks;
  var blockKeys = [];
  var asset = jsonResponse.items[i].views.html.slots.banner.blocks.blockKeys.assetType;
  var assetName = asset.name
    
   for (var blockKey in block) {
       blockKeys.push(blockKey);
      } 
    Write("\n\Name: " + emailName);
    Write("\n\Blocks: " +(blockKeys));
    Write("\n\Asset Name: " + assetName);

And this is the response

Name: Test Email Dinamico
Blocks: hmjsixa2nda,74tda2do8en
Asset Name: undefined

Someone knows what is wrong?

1 Answer 1

0

The most likely explanation is that jsonResponse.items[i].views.html.slots.banner.blocks.blockKeys.assetType.name is undefined in the JSON response.

If you can provide a sample JSON response, we could confirm this.

1
  • 1
    Thank you for your response, I resolved in this way for (var i = 0; i < jsonResponse.items.length; i++) { var email = jsonResponse.items[i]; var emailName = email.name; var block = jsonResponse.items[i].views.html.slots.banner.blocks; var blockKeys = []; for (var blockKey in block) { blockKeys.push(blockKey); var asset = jsonResponse.items[i].views.html.slots.banner.blocks[blockKey]; var assetName = asset.assetType.name; I was using in bad way de array with de blocksKeys
    – Juan
    Commented Jul 17, 2023 at 13:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .