0

I have a JSON string which I then convert into JSON Object by using jQuery. The string in question given below:

  var json = [
      {
        "1240": [
          "Order1",
          "user1"
        ]
      }
    ]

Here key 1240 is Dynamic and I can't do something like json[0]["1240"] When I do something like:

for(var f in json )
      {
          alert(f);
      }

Then it returns "0"

How do I fetch 1240 here?

1
  • 1
    Of course it's 0 since it's json[0]. If you want to reach "1024", you need for(var i in json[0]) Commented Sep 26, 2013 at 8:34

2 Answers 2

1

Because it's an array of objects.

http://jsbin.com/umaWoge/1/

Try this

    var json = [
      {
        "1240": [
          "Order1",
          "user1"
        ]
      }
];

for (var i = 0; i < json.length; i++)
{
  for(var f in json[i])
      {
          alert(f);
      }
}
Sign up to request clarification or add additional context in comments.

Comments

0
try this also.

var json = [
      {
        "1240": [
          "Order1",
          "user1"
        ]
      }
];

for (var i in json)
{
  for(var f in json[i])
      {
          alert(f);
      }
}

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.