-3

I'm trying to access a list of Casino Games and their properties from a JSON object in order to get them to display on the website. This is where I am so far.

var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);
console.log(x);

function ProcessProgressiveGames(progressiveGames) {
     console.log(progressiveGames.d.Games[0].GameName);
}

What's there best way to do this. If you check your console, you'll see that var x contains the object with the game data.

See also: http://pasteboard.co/kXb1Voq.png Related fiddle: http://jsfiddle.net/emporio/vz24dtm8/5/

This question is unique because it requires accessing unique properties. The answers also provide a multitude of ways to retrieve the data.

Marco V
  • 2,553
  • 8
  • 36
  • 58
  • 1
    Make your question more generic, and you wouldn't even need to make a question. – Kriggs Sep 02 '15 at 11:20
  • possible duplicate of [How to get all properties values of a Javascript Object (without knowing the keys)?](http://stackoverflow.com/questions/7306669/how-to-get-all-properties-values-of-a-javascript-object-without-knowing-the-key) – Kriggs Sep 02 '15 at 11:21
  • **Advice:** Please use [proper style conventions](http://javascript.crockford.com/code.html#names) with your function and variable names. `ProcessProgressiveGames` looks like an object definition. Instead use something like `processGamesOnSuccess` as the name. Be more descriptive. JavaScript is not C#. – Mr. Polywhirl Sep 02 '15 at 11:24
  • ok thanks! Will do that next time – Marco V Sep 02 '15 at 21:15
  • I don't see why this question is too broad. I have provided the link to the JSON object. I just needed to extract the data and I've been helped. My problem is solved. – Marco V Sep 03 '15 at 09:20

4 Answers4

1

DEMO

JS

var Games;
var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", function (data) {
    Games = data.d;
}).done(function () {
    document.getElementById('choice').innerHTML=ProcessProgressiveGames(Games);
});

function ProcessProgressiveGames(progressiveGames) {
    return progressiveGames.Games[0].GameName;
}
J Santosh
  • 3,808
  • 2
  • 22
  • 43
0

$.getJSON function returns promise and the proper way to handle data returned from this address is to set second argument - function to handle data

$.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);

function ProcessProgressiveGames(progressiveGames) {
    // Note that progressiveGames has a property 'd' containing the data we're interested in.
    console.log(progressiveGames);
    document.getElementById('choice').innerHTML = ProcessProgressiveGames(x);
     return progressiveGames.d.Games[0].GameName;
}

http://jsfiddle.net/vz24dtm8/7/

suvroc
  • 3,058
  • 1
  • 15
  • 29
0

You can try like this

var x = $.getJSON("http://api.bosurl.net/V1/Progressive.asmx/GetProgressiveGames?format=json&callback=?", ProcessProgressiveGames);

http://jsfiddle.net/vz24dtm8/8/

function ProcessProgressiveGames(data) {
    // Note that progressiveGames has a property 'd' containing the data we're interested in.

     return document.getElementById('choice').innerHTML=data.d.Games[0].GameName;

}
Man Programmer
  • 5,300
  • 2
  • 21
  • 21
0
    <pre>Use callback function to get the json value and pass the parameter in callback function</pre>

http://jsfiddle.net/rajen_ranjith/vz24dtm8/13/