2010-04-09 4 views

Répondre

4

Json.NET possède cette fonctionnalité.

0

Ajoutez le package JSON NuGet de Newtonsoft dans votre solution. Ajoutez ci-dessous la fonction et transmettez le schéma et votre réponse json dans la chaîne à la fonction ci-dessous.

public void ValidateSchema(JsonSchema JSchema, string JsonString) { 
     JsonString = JsonString.Replace("\"", "'"); 
     var ArrJobj = JArray.Parse(JsonString); 

     foreach (JObject jo in ArrJobj) 
     { 
      if (!jo.IsValid(JSchema)) throw new Exception("Schems Validation failed"); 

     } 

    } 

Hope this helps

5

Une alternative libre et open-source à Json.NET est NJsonSchema (schéma JSON projet 4).

Questions connexes