-4

I am trying to iterate this type json format, i tried to follow this method bit confused with my code How to iterate JSON array in JavaScript?.

and also i have an doubt, is this realy a json format or some thing else because i never seen such formats

 {  
   "pageId":"2001",
   "segments":"15",
   "cacheable":"Y",
   "compagedetailsails":[  
      {  
         "compid":"MOTP_HELP_TXT",
         "masterkey":"104_MOTP_HELP_TXT",
         "pagedetails":[  
            {  
               "key":"MOTP_HELP_TXT",
               "val":[  
                  "One Time Password has been sent to your mobile number. Click on resend in XXX seconds."
               ]
            }
         ]
      },
      {  
         "compid":"MOTP_EXP_SEC",
         "masterkey":"104_MOTP_EXP_SEC",
         "pagedetails":[  
            {  
               "key":"MOTP_EXP_SEC",
               "val":[  
                  "120"
               ]
            }
         ]
      },
      {  
         "compid":"MOTP_SUCC_ACT",
         "masterkey":"104_MOTP_SUCC_ACT",
         "pagedetails":[  
            {  
               "key":"MOTP_SUCC_ACT",
               "val":[  
                  "LMONUSPR"
               ]
            }
         ]
      },
      {  
         "compid":"bcksignotp",
         "masterkey":"104_bcksignotp",
         "pagedetails":[  
            {  
               "key":"N104_bcksignotp0",
               "val":[  
                  "mxback"
               ]
            },
            {  
               "key":"N104_bcksignotp1",
               "val":[  
                  ""
               ]
            },
            {  
               "key":"N104_bcksignotp2",
               "val":[  
                  "0"
               ]
            }
         ]
      }



   ]
}
4
  • 2
    what exactly are you struggling with? Post the code you have written so far. And yes, the data you've given is JSON. I haven't checked whether it's valid, but it certainly looks like the right format. Commented Jun 20, 2016 at 13:06
  • I am trying to render each value by using masterkey Commented Jun 20, 2016 at 13:23
  • you still need to post your code. That isn't a sufficient description for anyone to see where the problem might be. Equally, you're unlikely to get any help if you don't show that you have made some effort to solve the problem yourself. Commented Jun 20, 2016 at 13:25
  • Please specify the context(code) in order for anyone to answer your question. Commented Jun 20, 2016 at 13:28

1 Answer 1

0

a = {  
   "pageId":"2001",
   "segments":"15",
   "cacheable":"Y",
   "compagedetailsails":[  
      {  
         "compid":"MOTP_HELP_TXT",
         "masterkey":"104_MOTP_HELP_TXT",
         "pagedetails":[  
            {  
               "key":"MOTP_HELP_TXT",
               "val":[  
                  "One Time Password has been sent to your mobile number. Click on resend in XXX seconds."
               ]
            }
         ]
      },
      {  
         "compid":"MOTP_EXP_SEC",
         "masterkey":"104_MOTP_EXP_SEC",
         "pagedetails":[  
            {  
               "key":"MOTP_EXP_SEC",
               "val":[  
                  "120"
               ]
            }
         ]
      },
      {  
         "compid":"MOTP_SUCC_ACT",
         "masterkey":"104_MOTP_SUCC_ACT",
         "pagedetails":[  
            {  
               "key":"MOTP_SUCC_ACT",
               "val":[  
                  "LMONUSPR"
               ]
            }
         ]
      },
      {  
         "compid":"bcksignotp",
         "masterkey":"104_bcksignotp",
         "pagedetails":[  
            {  
               "key":"N104_bcksignotp0",
               "val":[  
                  "mxback"
               ]
            },
            {  
               "key":"N104_bcksignotp1",
               "val":[  
                  ""
               ]
            },
            {  
               "key":"N104_bcksignotp2",
               "val":[  
                  "0"
               ]
            }
         ]
      }



   ]
}
for(var i = 0; i < a.compagedetailsails.length; i++)
{
  console.log(a.compagedetailsails[i]);
}

You can iterate something like this and through this you can access each element and its attributes. I hope it helps ! Furthermore you can access anything in the Json using dot operator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.