Click here to Skip to main content
15,879,239 members
Articles / Web Development / ASP.NET

JSON Data Visualizer (for Google, Yahoo!, Bing, and Twitter) using jQuery, JavaScript, ASP.NET MVC 2.0

Rate me:
Please Sign up or sign in to vote.
4.83/5 (14 votes)
29 Jun 2010CPOL6 min read 72.5K   898   46  
This article describes a JSON data visualizer for popular Web Services like Google, Yahoo!, Bing, and Twitter using jQuery, JavaScript, and ASP.NET MVC 2.0.
var param_count = 0;
var search_engines1 =
{
    "Google": {
    "urlengine": "http://ajax.googleapis.com/ajax/services/search/web?v=1.0",
    "parameter": { "&q": "pizza 94539" }
    }
,
//Yahoo
  "Yahoo": {
  "urlengine": "http://local.yahooapis.com/LocalSearchService/V3/localSearch?output=json",
  "parameter": { 
        "&query": "pizza",
        "&zip": "94539",
        "&results": "2"
               }
            }
,
//Bing
"Bing": {
    "urlengine": "http://api.search.live.net/json.aspx?sources=web",
    "parameter": { 
        "&query":"pizza 94539",
        "&count":"2"
    }
}
,
//Twitter
"Twitter": {
    "urlengine": "http://search.twitter.com/search.json?",
    "parameter": { 
        "&q":"windows phone 7"
    }
}

 
}
//

 //
function Build_Engine() {
    // jQuery.each(search_engines, function (key, val) { recursiveFunction(key, val) });
    $('#buildenginediv').empty();
    var s = $('#select_engine_select')[0]; //Select the select box
    s.length = 0; //empty out the select box
    var iselect = 0;
    $.each(search_engines1, function (key, val) 
            {
            var op = new Option(key); //Create "Option i" with a value of i
             s[iselect] = op; //Add "Option i" at index i
             iselect++;
           }

         )
          // $('#buildenginediv').append( $("#select_engine_select option:selected")[0].value);
}

function Build_Engine1() {
    $('#buildenginediv').empty();
    var params = $("#select_engine_select option:selected")[0].value;
    var parameter_selected = search_engines1[params];
    param_count = 0;
    $.each(parameter_selected['parameter'], function (key, val) {

        $('#buildenginediv').append('<input id="Key' + param_count + '" type="text" readonly="readonly" style="width: 150px" value="' + key + '"/>' + '<input id="Text' + param_count + '" type="text" style="width: 400px" value="' + val + '"/> <br/>');
        param_count++;
    })
}
function Get_Engine_Data(divname) {
    var searchengine_selected = $("#select_engine_select option:selected")[0].value;
    var parameter_selected = search_engines1[searchengine_selected];
    var urlengine = parameter_selected["urlengine"];
    var param1 = '';
    for (var iparamcount = 0; iparamcount < param_count; iparamcount++) {
        var textboxid = '#Text' + iparamcount;
        var keyid = '#Key' + iparamcount;
         param1 +=  $(keyid).val() + '=' + $(textboxid).val();
    }
     Clear_AllData();

     var selecteditems = { "searchengine": searchengine_selected, "parameter": param1, "url1": urlengine };

     jQuery.getJSON('/Json/JsonData1', selecteditems, function (result) {

         displayresult(result, divname, selecteditems);
     })

 }
 //display result
 function displayresult(result, divname, selecteditems) {
     $('#headerdiv').append("<hr/>" + "Results From: " + selecteditems["searchengine"] + " : " + " Parameters: " + selecteditems["url1"] + selecteditems["parameter"] + "<hr/>");

     switch (divname) {
         case '#rawdatadiv':
             $(divname).append(result);
             break;
         case '#tabledatadiv':
             data = $.parseJSON(result);
             var tbl = prettyPrint(data);
             $(divname).append(tbl);
             break;
         case '#beautifydiv':
             $(divname).show();
             beautifyresult(result);
             break;
         case '#JsonListdiv':
             result1 = '{"datamade":' + result + '}';
             data = $.parseJSON(result1);
             folderarray = new Array();
             BuildTree(data, "datamade", 0);
             break;

         default:
             break;
     }
     $('#footerdiv').append("<hr/>" + "done" + "<hr/>");
 }

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Vijay Kumar: Architect, Programmer with expertise and interest in Azure, .net, Silverlight, C#, WCF, MVC, databases and mobile development. Concentrating on Windows Phone 7 and Windows Azure development. Lived in California for many years and done many exciting projects in dotnet and Windows platforms. Moved to Raleigh (RTP), North Carolina recently and available for consulting.  Blog http://Silverazure.blogspot.com.

Comments and Discussions