[ACCEPTED]-What does .d in JSON mean?-json

Accepted answer
Score: 24

Are you referring to the ADO.NET Data Services?

I 7 remember hearing a presentation about the 6 JSON returning this and I think its just 5 a wrapper to ensure the payload is a JSON object as opposed to an array (which 4 is the case of returning multiple entities).

Why 3 'd' specifically? I think I remember them 2 saying something like 'well it had to be 1 something'.

Score: 10

Based on this tutorial: JSON Web Service And jQuery with Visual Studio 2008

The Web Method returns 11 a Product that is serialized in JSON format. Since 10 there is not JSON type, the returned value is 9 a String with JSON format.

On the client side, the 8 ajax call returns a JSON.

The result looks 7 like {d: 'returned-string-with-JSON-format'}

More exactly something like: {d:'{"ID":123,"Name":"Surface Pro 2"}'}

Note 6 that 'returned-string-with-JSON-format' is a string not a JSON object so you 5 cannot do result.d.ID.

Instead you need to convert it to JSON 4 object by using JSON.parse(result.d) or eval(result.d)

At the end, what you 3 really want is do this:

result = JSON.parse(result.d)

UPDATE Also consider this 2 demo, where I use a JSON in string format 1 and convert it to JSON object:

enter image description here

Score: 2

ASPX Code Here:

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <script type="text/javascript">


        function GetData()
        {
            alert("I am called");
                $.ajax({
                    type: "POST",
                    url: "Contact.aspx/GetProducts",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {


                       var data = JSON.parse(result.d)
                       alert(data.Id);

                    },
                    error:function(ex)
                    {
                        alert("Test");
                    }
                });
        }
    </script>

     <asp:TextBox ID="txtName" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetData();" />
</asp:Content>

C# Code Here:

public partial class Contact : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
            int[] arr1 = new int[] { 1, 2 };
            ListBox1.SelectedValue = "1";
            ListBox1.SelectedValue = "4";


        }

        void BindList()
        {

            List<Product> lst = new List<Product>()
            {
                new Product{Id=1,Name="Photo"},
                new Product{Id=2,Name="Photo"},
                new Product{Id=3,Name="Photo"},
                new Product{Id=4,Name="Photo"}
            };
            ListBox1.DataSource = lst;
            ListBox1.DataTextField = "Name";
            ListBox1.DataValueField = "Id";
            ListBox1.DataBind();
        }


        [WebMethod]
        public static string GetProducts()
        {
            // instantiate a serializer
            JavaScriptSerializer TheSerializer = new JavaScriptSerializer();

            //optional: you can create your own custom converter
           // TheSerializer.RegisterConverters(new JavaScriptConverter[] { new MyCustomJson() });

            //var products = context.GetProducts().ToList();
            Product products = new Product() { Id = 1, Name = "Testing Services" };
            var TheJson = TheSerializer.Serialize(products);

            return TheJson;
        }

    }

0

Score: 1

may be very much useful link for those who 5 want to really learn from scratch an example 4 about wrapper class where the details in 3 one class can never be dislosed to other 2 class but can be indirectly accessed through 1 various methods http://www.c-sharpcorner.com/Blogs/12038/wrapper-class-in-C-Sharp.aspx

Score: 0

It returns the value of the field named 2 'd' in the object 'result'.

This question shows an example of 1 how the JSON might look, notice the d: field.

Score: 0

The d is part of the result returned by 5 your .NET code. If you look at this code 4 you should see a variable being set with 3 the name d. If it is generated from serialized 2 classes, then it probably sends along a 1 member of that class with the name d.

Score: 0

As others have pointed out, it returns the 2 "d" member of the "result" object.
If you wanted to 1 have "d" in a variable you could use this:

var property = "d";
var value = result[property];
Score: 0

Its is very clear that $("#div").html(result.d); in 5 your code

"result" is a object and d is property 4 of "result".

Let explain,

if you create object 3 like this,

var result{"id": "number", "d": "day"};

if we access the property of result 2 is that using jquery

$("#div").html(result.d);

so we get result in 1 html is

<html>day</html>

More Related questions