• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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
0
rajneesh1978
Asked:
rajneesh1978
  • 4
  • 4
2 Solutions
 
Om PrakashCommented:
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
 
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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
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
 
leakim971PluritechnicianCommented:
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now