Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Jarray #tryparse
ADD COMMENT
Topic
Name
4+6 =