Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Manatee.Json;
- string jsonObjStr = "{\"attr0\":\"text here\", \"attr1\":{\"attr2\":5}}";
- //Parse json strings
- JsonValue jsonObj = JsonValue.Parse(jsonObjStr);
- JsonValue jsonSchemaObj = JsonValue.Parse(jsonSchemaObjStr);
- JsonSchema schema = new JsonSerializer().Deserialize<JsonSchema>(jsonSchemaObj);
- //Validate schema
- MetaSchemaValidationResults schemaResult = schema.ValidateSchema();
- //Validate json object
- SchemaValidationResults result = schema.Validate(data);
- if(result.IsValid)
- {
- //Access elements
- string zero = jsonObj.Object["attr0"].String;
- int one = (int) jsonObj.Object["attr1"].Object["attr2"].Number;
- //Check type of element
- if(jsonObj.Object["attr0"].Type == JsonValueType.String)
- ...
- }
- //Dynamically create json object
- JsonObject obj = new JsonObject();
- obj.Add("mykey", new JsonValue("myvalue"));
- string jsonStr = obj.ToString();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement