I am trying to do a JSON schema validation dynamically. We are taking the JSON from an uploaded file and trying to validate this is exact JSON or not. This is an On premise application.I cannot use JSON.net. I cannot install any other third party tools to validate this. I have tried two ways as below.
1.I used System.Web.Helper and Using the below code, i am getting the error
code :
var jsonstring = "{\"user\":{\"name\":\"asdf\",\"age\":\"26\",\"teamname\":\"b\",\"email\":\"c\",\"players\":[\"1\",\"2\"]}}";
var jsonObject = Json.Decode(jsonstring);
Error is "Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed". I searched for solutions and found that we need to uncheck a check box in debug properties of solution.But this only works in Console application for me.But not working in our VS 2012 solution. Is there any way to solve this issue?
- Next is, i tried to use JavaScriptSerializer as given below and successfully got the results in my objJson.
JavaScriptSerializer serializer = new JavaScriptSerializer();
string inputContent;
StreamReader inputStreamReader = new StreamReader(FileUploadControl.PostedFile.InputStream);
inputContent = inputStreamReader.ReadToEnd();
inputContent = inputContent.Replace("\r", "").Replace("\n", "").Replace("\t", "");
var objJson= serializer.Deserialize>(inputContent);
But when i am trying to get values of this resulted key values pair, i am getting error as in image. Error is Dynamic operations can only be performed in homogenous AppDomain. for this the solution found was to change the attribute "legacyCasModel=true" to "legacyCasModel=false" in web.config file. But as this is OnPremise application i cannot change this attribute.Please help on this.