3

I had found json url for live display of scores

http://json-cricket.appspot.com/score.json

Output of json:

{
 "batting_team": "Canada", "date": "Feb 28, 2011",
 "match": "Canada vs Zimbabwe", "score": "Canada 106-8 (37)",
 "summary": "Z Surkari(21) H Baidwan(3)*" 
}

I don't know how to fetch and display the data in my site I am using following codes:

$.getJSON("http://json-cricket.appspot.com/score.json", function (data) {
    $.each(data, function (i, set) {
        alert("Batting Team: "+set.batting_team);
    });
});

Please mention me what wrong I did. I can't get the data from json. I am not being able to connect to the site.

Thanks in advance

S L
  • 14,262
  • 17
  • 77
  • 116
Mohan Ram
  • 8,345
  • 25
  • 81
  • 130
  • Why json not works i need to know. Once i give this url in address bar i can see results of json but. while using getJson in doesnt connects to that url. why? – Mohan Ram Feb 28 '11 at 11:17

2 Answers2

2

You probably mean to do something more like:

for(var item in data) {
    alert(item + ':' + data[item]);
}

This gives you messages like "batting_team : Canada" and "date : Feb 28, 2011" which is probably more what you want.

Neil
  • 5,762
  • 24
  • 36
  • First of all i cant connect to that json url @neil. Once i use url json values displayed but through jquery once i used in my site i cant connect to that json. Help me with working emaples – Mohan Ram Feb 28 '11 at 11:02
  • I'm afraid I don't understand what you mean. Save data to a local variable so you have to use and reuse as you require. Did that answer your question? – Neil Feb 28 '11 at 11:42
2

Hey I Fetched cricket score using this,

var url="http://json-cricket.appspot.com/score.json?callback=?";
$.getJSON(url, function (data) {
    for(var item in data) {
        alert(item + ':' + data[item]);
    }
});
Mohan Ram
  • 8,345
  • 25
  • 81
  • 130