Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Sample Json String:-

{d: "{"name":{"Fname":"test","LName":"data"},"Address":{"address1":"abc","address2":"def","pincode":"0","Area":"Bhandup"}}"}



Name data should be append in
tblname
table an address data should be append in
tblAddress
table kindly help

What I have tried:

<pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JsonDisplay.aspx.cs" Inherits="JSON1.JsonDisplay" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-2.1.4.js"></script>
   <%-- <script src="Scripts/jquery-2.1.4.min.js"></script>--%>
    <script type="text/javascript">
        $(document).ready(function () {

            debugger;
            //alert(1);
            $('#Getdata').click(function () {

                alert(2);

               $.ajax({
                type: "POST",
                url: "JsonDisplay.aspx/DisplayData",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: { },
                   success: function (msg) {
                       debugger;
                       var data = JSON.stringify(msg);
                       var jdata = JSON.parse(data);

                       var i = 0;

                       var trHTML = '';

                       $.each(jdata, function (i, item) {
        
                             trHTML += '<tr><td>' + data.jdata[i] + '</td><td>' + data.jdata[i] + '</td></tr>';
                        });
                     
                     $('#tblname').append(trHTML);
                }
            })
            })

        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <%--<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />--%>
       <input type="button" name="btn1" id="Getdata" value="Getdata" />
        <div id="name">
            <table id="tblname">

            </table>
        </div>
        <div id="Addess">
            <table id="tblAddress">

            </table>
        </div>
    </form>
</body>
</html>
Posted
Updated 1-Feb-19 20:23pm
v2
Comments
[no name] 4-Feb-19 12:15pm    
Thanks for reminding me again why I don't do web clients.
Richard Deeming 4-Feb-19 12:50pm    
var data = JSON.stringify(msg);
var jdata = JSON.parse(data);

Why?!

1. jQuery takes the JSON returned from the server, and parses it into an object for you.
2. You than convert that object back to JSON.
3. You then parse that JSON back into an object.

Just use the msg parameter instead.
Richard Deeming 4-Feb-19 12:51pm    
Also:
trHTML += '<tr><td>' + data.jdata[i] + '</td><td>' + data.jdata[i] + '</td></tr>';

Your data variable is a string. It doesn't have a property called jdata.
dattaprasaddhuri 8-Feb-19 0:16am    
Thank you. Its working

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900