0

I am learning how to parse json and query and was looking at other questions: I saw that someone was using the below URL to get ticker symbols and values. I also wanted to get the actual stock value, but I will figure that out later.

My jquery code is supposed to parse the JSON format that it gives but I am new at this and it doesn't seem to be working the way I understand it to work. Sorry if this is a bit of a "nooby" question.

http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=yahoo&callback=YAHOO.Finance.SymbolSuggest.ssCallback

It returns this, I reformatted it and validated it to make it readable and to check it:

YAHOO.Finance.SymbolSuggest.ssCallback({
   "ResultSet":{
      "Query":"google",
      "Result":[
         {
            "symbol":"GOOG",
            "name":"Google Inc.",
            "exch":"NMS",
            "type":"S",
            "exchDisp":"NASDAQ",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GOOG.MX",
            "name":"Google Inc.",
            "exch":"MEX",
            "type":"S",
            "exchDisp":"Mexico",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GGQ1.DE",
            "name":"GOOGLE-A",
            "exch":"GER",
            "type":"S",
            "exchDisp":"XETRA",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GGQ1.SG",
            "name":"GOOGLE-A",
            "exch":"STU",
            "type":"S",
            "exchDisp":"Stuttgart",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GGQ1.HA",
            "name":"GOOGLE-A",
            "exch":"HAN",
            "type":"S",
            "exchDisp":"Hanover",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GGQ1.MU",
            "name":"GOOGLE-A",
            "exch":"MUN",
            "type":"S",
            "exchDisp":"Munich",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GGQ1.F",
            "name":"GOOGLE-A",
            "exch":"FRA",
            "type":"S",
            "exchDisp":"Frankfurt",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GOOG11BF.SA",
            "name":"GOOGLE      -DRN     MB",
            "exch":"SAO",
            "type":"S",
            "exchDisp":"Sao Paolo",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GOOF.EX",
            "name":"GOOGLE-A",
            "exch":"EUX",
            "type":"S",
            "exchDisp":"EUREX Futures and Options Exchange ",
            "typeDisp":"Equity"
         },
         {
            "symbol":"GGQ1.HM",
            "name":"GOOGLE-A",
            "exch":"HAM",
            "type":"S",
            "exchDisp":"Hamburg",
            "typeDisp":"Equity"
         }
      ]
   }
})

this is the part of my code to parse that url exactly:

function(data) {
                  $("#quotes").empty();
                  $.each(data.query.search, function(i, Result){
                    $("#quotes").append("<div>" + ResultSet.Result.symbol + "</a><br>" + ResultSet.Result.name + "<br><br></div>");
                  });
                });
  • what is `query.search`, data is the JSON Object, `query` is listed as `Query` and is case sensitive, so that won't work, and `search` is not a `key` with your `json`. – Ohgodwhy Jul 08 '12 at 22:52

1 Answers1

0

Based on what you're trying to achieve with the code above, and the JSON structure, you would like to iterate over each Result and retrieve the properties of that object, then output them as a div, here you go:

$.each(data.ResultSet.Result, function(i, Result){  
  $("#quotes").append("<div>Symbol: "+Result.symbol+", Name: "+Result.name+" <br/><br/></div>");
});

Here is the working jsFiddle

Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110