1

Sorry for my english,

I have following JSON literal notation.

[
  {
    "ktp_app": [
      "hantong",
      "hantong4",
      "hantong2",
      "hantong3"
    ],
    "ktp_apps":[
      "kun1"
    ]
  }
]

I parsed this with eval // var tmp = eval(jsondata);

i could access first array of data which means

{"ktp_app":["hantong","hantong4","hantong2","hantong3"],"ktp_apps":["kun1"]}**

but after that, how could i access the other part of json data,. only way i could access is to use a

tmp[0]["ktp_app"] ... but i want to access without String., i want use loop so that i can access all of the data;..

thanks in advance.

2 Answers 2

4

You can use the . operator. So:

json = [
  {
    "ktp_app": [
      "hantong",
      "hantong4",
      "hantong2",
      "hantong3"
    ],
    "ktp_apps":[
      "kun1"
    ]
  }
]

json[0].ktp_app[0] would give "hantong".

Alternatively you can do it like this:

json[0]["ktp_app"][0] would give "hantong"

In a loop:

for (name in json[0]) {
  var elem = json[0][name]
}
Sign up to request clarification or add additional context in comments.

Comments

1

Here is a way to loop over the values in you data object:

var data = [
  {
    "ktp_app": [
      "hantong",
      "hantong4",
      "hantong2",
      "hantong3"
    ],
    "ktp_apps":[
      "kun1"
    ]
  }
];
for (key in data[0]) { 
  console.log(data[0][key]); 
}

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.