Answers for "c# Jarray tryparse"

C#
0

c# Jarray tryparse

public static T TryParseJson<T>(this string json, string schema) where T : new()
{
    JsonSchema parsedSchema = JsonSchema.Parse(schema);
    JObject jObject = JObject.Parse(json);

    return jObject.IsValid(parsedSchema) ? 
        JsonConvert.DeserializeObject<T>(json) : default(T);
}

// Usage:
var myType = myJsonString.TryParseJson<AwsomeType>(schema);
Posted by: Guest on May-27-2021

C# Answers by Framework

Browse Popular Code Answers by Language