RE : ASP.net

Hi,

Can you please help to know me what is the best way to achieve below:-

1) Generate XML from SQL server (which format is easy for conversion to JSON)
2) Convert XML to JSON in C# (Any custom class which will handle all types of XML conversion to JSON)
3) Parse the JSON on client side

Thanks
rajneesh1978Asked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
new one : http://jsfiddle.net/C7tCF/3/
var json = {"Constituency":{"Years":{"ConstituencyInfo":{"Collection":"7910.99","ConstituencyName":"CONSTITUENCY PASIR RIS EAST","RCNameInfo":{"Collection":"6359.99","RCName":"RC PASIR RIS ZONE 1","RespectiveRCInfo":[{"Collection":"0.00","Month":"Jan"},{"Collection":"0.00","Month":"Feb"},{"Collection":"0.00","Month":"Mar"},{"Collection":"0.00","Month":"Apr"},{"Collection":"0.00","Month":"May"},{"Collection":"0.00","Month":"Jun"},{"Collection":"6359.99","Month":"Jul"},{"Collection":"0.00","Month":"Aug"},{"Collection":"0.00","Month":"Sep"},{"Collection":"0.00","Month":"Oct"},{"Collection":"0.00","Month":"Nov"},{"Collection":"0.00","Month":"Dec"}]}},"Year":"2011"}}};

window.onload = function() {
    var _r = document.getElementsByTagName("tr");
    _r[0].getElementsByTagName("td")[0].innerHTML = json.Constituency.Years.Year;
    _r[2].getElementsByTagName("td")[0].innerHTML = json.Constituency.Years.ConstituencyInfo.ConstituencyName;
    _r[2].getElementsByTagName("td")[1].innerHTML = json.Constituency.Years.ConstituencyInfo.RCNameInfo.RCName;
    for(var i=0;i<json.Constituency.Years.ConstituencyInfo.RCNameInfo.RespectiveRCInfo.length;i++) {
        _r[2].getElementsByTagName("td")[2+i].innerHTML = json.Constituency.Years.ConstituencyInfo.RCNameInfo.RespectiveRCInfo[i].Collection;    
    }
    _r[2].getElementsByTagName("td")[14].innerHTML = json.Constituency.Years.ConstituencyInfo.RCNameInfo.Collection;    
}

Open in new window

0
 
Om PrakashConnect With a Mentor Commented:
0
 
leakim971PluritechnicianCommented:
1) Generate XML from SQL server (which format is easy for conversion to JSON)
http://www.sitepoint.com/data-as-xml-sql-server/

2) Convert XML to JSON in C# (Any custom class which will handle all types of XML conversion to JSON)
http://www.phdcc.com/xml2json.htm

3) Parse the JSON on client side
We can use PageMethods and a webservice to retrieve the JSON object
http://www.dotnetfunda.com/articles/article454-using-pagemethods-and-json-in-aspnet-ajax.aspx

Sample of (2) :
{ "space":
  { "name": "Cake Collage",
    "frame": [ {"photo": { "img": "cakecollage1.jpg" },
...

Open in new window


For example, we want to alert the value of first img key :
        function OnRequestComplete(result, userContext, methodName) {
             var result = eval('(' + result + ')');
             var frame = result.space.frame;
             alert(frame[0].photo.img);
        }

Open in new window

or another example, we want to alert all photo img :
        function OnRequestComplete(result, userContext, methodName) {
             var result = eval('(' + result + ')');
             var frame = result.space.frame;
             for(var i=0;i<frame.length;i++) {
                  alert(frame[0].photo.img);
             }
        }

Open in new window

or another example, we want to alert all type of the second rule :
        function OnRequestComplete(result, userContext, methodName) {
             var result = eval('(' + result + ')');
             var frame = result.space.frame;
             for(var j in frame[1].rule) {
                  alert(j.type);
             }
        }

Open in new window

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
rajneesh1978Author Commented:
Please let me know how can parse the data as below in Javascript

{
   "Constituency": {
      "Years": {
         "ConstituencyInfo": {
            "Collection": "7910.99",
            "ConstituencyName": "CONSTITUENCY PASIR RIS EAST",
            "RCNameInfo": {
               "Collection": "6359.99",
               "RCName": "RC PASIR RIS ZONE 1",
               "RespectiveRCInfo": [
                  {
                     "Collection": "0.00",
                     "Month": "Jan"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Feb"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Mar"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Apr"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "May"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Jun"
                  },
                  {
                     "Collection": "6359.99",
                     "Month": "Jul"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Aug"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Sep"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Oct"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Nov"
                  },
                  {
                     "Collection": "0.00",
                     "Month": "Dec"
                  }
               ]
            }
         },
         "Year": "2011"
      }
   }
}


I would like to show the data as per attached



Sample.xlsx
0
 
leakim971PluritechnicianCommented:
Eh, good to know you're alive!
Check this test page : http://jsfiddle.net/C7tCF/

Are you using jQuery? The code can be a bit simplified in this case...


var json = {"Constituency":{"Years":{"ConstituencyInfo":{"Collection":"7910.99","ConstituencyName":"CONSTITUENCY PASIR RIS EAST","RCNameInfo":{"Collection":"6359.99","RCName":"RC PASIR RIS ZONE 1","RespectiveRCInfo":[{"Collection":"0.00","Month":"Jan"},{"Collection":"0.00","Month":"Feb"},{"Collection":"0.00","Month":"Mar"},{"Collection":"0.00","Month":"Apr"},{"Collection":"0.00","Month":"May"},{"Collection":"0.00","Month":"Jun"},{"Collection":"6359.99","Month":"Jul"},{"Collection":"0.00","Month":"Aug"},{"Collection":"0.00","Month":"Sep"},{"Collection":"0.00","Month":"Oct"},{"Collection":"0.00","Month":"Nov"},{"Collection":"0.00","Month":"Dec"}]}},"Year":"2011"}}};

window.onload = function() {
    var _r = document.getElementsByTagName("tr");
    _r[0].getElementsByTagName("td")[0].innerHTML = json.Constituency.Years.Year;
    _r[2].getElementsByTagName("td")[0].innerHTML = json.Constituency.Years.ConstituencyInfo.ConstituencyName;
    _r[2].getElementsByTagName("td")[1].innerHTML = json.Constituency.Years.ConstituencyInfo.RCNameInfo.RCName;
    for(var i=0;i<json.Constituency.Years.ConstituencyInfo.RCNameInfo.RespectiveRCInfo.length;i++) {
        _r[2].getElementsByTagName("td")[1+i].innerHTML = json.Constituency.Years.ConstituencyInfo.RCNameInfo.RespectiveRCInfo[i].Collection;    
    }
}

Open in new window

0
 
rajneesh1978Author Commented:
Hi,

Please find attached JSON data and need to read in loop and fix into below format.
Below format need to created through Jquery and value need to be included where i Mentioned value from Json data

Please let me know how can i do.
Problem is that we need to do in loop from main module as well as Sub module.

<div class='container'>
      <div class='mainDiv'>
            <div class='topItem'>
                  module_desc(Value from Json data)
            </div>
            <div class='dropMenu'>
                  <div class='subMenu' style='display:inline;'>
                        <div class='subItem'>
                              <a href='submodule_url(Value from Json data)'>submodule_desc (Value from Json data)</a>
                        </div>
                  </div>
            </div>
      </div>


      <div class='dropMenu'>
            <div class='subMenu' style='display:inline;'>
                  <div class='subItem'><a href='/inkcampaign/manager/logout.asp'><img SRC='/inkcampaign/manager/images/arrow-down.gif' WIDTH='14' HEIGHT='8' BORDER='0'>Log Off</a></div>
                  <script type='text/javascript' src='/inkcampaign/manager/js/xpmenuv21.js'></script>
            </div>
      </div>
</div>
Jsondata.txt
0
 
leakim971PluritechnicianCommented:
Hi,

Please close this question and open a new one.

Best Regards.
0
 
rajneesh1978Author Commented:
Thanks
0
 
rajneesh1978Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.