I can't seem to find any solution to this within SO so here goes.
I have a call to a WebMethod within the C# of my page like this;
$.ajax({
type: "POST",
url: "MyWebPage.aspx/jQueryMyWebMethod",
data: "{FamilyType:'" + $('.HdnFamilyType').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
var obj = eval('(' + msg + ')');
}
});
In the code behind I create an object, serialise it and return it like this;
LHCRequiredFormViewModel fvm = new LHCRequiredFormViewModel();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(LHCRequiredFormViewModel));
MemoryStream ms = new MemoryStream( );
ser.WriteObject(ms, fvm);
return Encoding.Default.GetString(ms.ToArray());
However, in the Javascript when I do the eval I get the error;
Expected ']';
At the point of returning the serialised object from C# the data looks like;
"{\"<IsApplicantLHCRequired>k__BackingField\":true,\"<IsPartnerLHCRequired>k__BackingField\":false}" string
I should mention that the project was .Net 2.0 and I was simply returning a serialised object w/out all the JSON guff and it worked fine.
So I then converted to 3.5 and the problem began. It's then that I used the JsonSerializer but am still getting exactly the same error.
Anyone know what's going on and how to fix it?