Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning a JSON object from a PageMethod with custom formatting

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": "[email protected]" } }

To
{ "name": "bob", email: "[email protected]" }

like image 564
Mark Clancy Avatar asked Nov 24 '25 06:11

Mark Clancy


1 Answers

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.

like image 171
Crescent Fresh Avatar answered Nov 26 '25 23:11

Crescent Fresh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!