Question

Is it possible to format how an object is returned as JSON from a PageMethod? ie. removing the first "d" element from the data, without writing the JSON from scratch.

From { "d": { "name": "bob", "email": "bob@example.com" } }

To { "name": "bob", email: "bob@example.com" }

Was it helpful?

Solution

No. Microsoft's JSON serializer adds the d for some reason on the server side, and the client-side AJAX code that deserializes the JSON string expects it to be there.

OTHER TIPS

The extra "d" parameter is added by the .NET framework as an added security measure against XSS attacks [source]. It's included when the "Content-Type" of the request specifies "application/json".

I think you can get the framework to exclude it (ie don't wrap the result in the "d") if you simply specifying the "Content-Type" of the request as something other than "application/json". Try removing that header from the request (if you can) and seeing what .NET returns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top