I have a JSON data, that I want to automatically find every occurrence of a specific name.
{
"servergenre": "Classic Rock",
"servergenre2": "pop",
"servergenre3": "rock",
"servergenre4": "jazz",
"servergenre5": "80s",
"serverurl": "http://www.name.com",
"servertitle": "ServerHero",
"bitrate": "48",
"samplerate": "0"
}
in here servergenre
is repeated a few times with increment (2,3,4,5 and ...
) as I do not know ho many servergenre
there will be in the JSON, I need a method to loop through it and find as many times as there are instances of servergenre
and add the result in an array possibly.
Something like this following code:
var URL = "http://name.com/file.json"
$.getJSON(URL, function(data) {
var i = 1;
$.each(data.servergenre + i, function(index, value) {
/// CODE
});
});
Obviously the code above does not work but that was my initial idea.
So any better idea to make it work and save all exisiting instances of servergenre
in an array?
Thank is advance.