json web service Get value from dynamic parameter's name

please i have this output from my json web service:

      {"format":"json",
       "success":true,
       "errors":[],
       "result":
       {"**206**":
         {"player_name":"stagiaire",
           "M":{
                "6480":{"score":0,"answer":"cdgvbdbgd","category_name":"cdgvbdbgd"},
                "6481":{"score":0,"answer":"cdgvbdbgd","category_name":"cdgvbdbgd"},
                "6482":{"score":0,"answer":"cdgvbdbgd","category_name":"cdgvbdbgd"},
                "6483":{"score":0,"answer":"cdgvbdbgd","category_name":"cdgvbdbgd"},
               },

          "O":{
                 ..... },
      }
     }
    } 

What i want is to extract the value (which is now 206 but it can be another number). I am asking for your help to achieve this goal. Any help will be appreciated.

Answers


In case the resulting object contains only a single property with this number as its name, i.e.

result = {
    206 : {
        ...
    }
    // no other properties here
}

then you can use something like:

var num = Object.keys(result).shift();  // "206"

Check the browser compatibility for Object.keys() method at MDN and use shim if needed.


If the object you look for always has a player name as value, try

for (var key in obj.result) if obj.result[key]["player_name") alert(key)

Or use jQuery

$.each(data.result,function(key,val) {
  alert(key);
});

Need Your Help

next Node in Node Class

java class

I have this node class, I was wondering how does the program recognize that the Node next is actually the next node? and why would I want to assign it to null please? Detailed explanation would be

MySQL PHP Hack Prevention / DB backup?

php mysql database security backup

Well, I finally finished my site (Just learned PHP and MySQL) So I'm wondering what are some of the most common ways hackers get in and how can I prevent it... I have already been informed of