how to prevent default serialization in a aspnet webform web method (not api or mvc) in order to user Json.net
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
[WebMethod]
public static object MyMethod()
{
dynamic field1 = new JObject();
field1.Alessio = "ciao";
return JsonConvert.SerializeObject(field1);
}
the output is:
{"d":"{\"Alessio\":\"ciao\"}"}
instead it should be
{"d":"{ "Alessio ": "ciao"}"}
because the serialization has been applied twice (from JsonConvert.SerializeObject and from the default serializer)
is there a way to: - disable the default serialization for a single webmethod? or - change the default serializer with Json.Net serializar only on a page or on a method? or - change the default serializer with Json.Net globally?
The project is a webform application (not an api or a mvc application) and is not intended to move WebMethods on a WCF or on a HttpHandler
{"d": { "Alessio": "ciao" } }instead?