19 using System.Collections.Generic;
21 using Newtonsoft.Json.Linq;
22 using Newtonsoft.Json;
37 if (
null == jtok)
throw new ArgumentNullException(
"jtok",
"jtok cannot be null.");
38 if (
string.IsNullOrEmpty(field))
throw new ArgumentNullException(
"field",
"field cannot be null.");
40 JToken child = jtok[field];
41 if (
null == child)
return null;
43 if (child.Type == JTokenType.String)
45 string value = child.ToString();
46 return value.Trim(
'\"');
60 if (
string.IsNullOrEmpty(value))
throw new SchemaParseException(
string.Format(
"No \"{0}\" JSON field: {1}", field, jtok));
72 ensureValidFieldName(field);
73 JToken child = jtok[field];
74 if (
null == child)
throw new SchemaParseException(
string.Format(
"No \"{0}\" JSON field: {1}", field, jtok));
76 if (child.Type == JTokenType.Integer)
return (
int) child;
88 if (
null == jtok)
throw new ArgumentNullException(
"jtok",
"jtok cannot be null.");
89 if (
string.IsNullOrEmpty(field))
throw new ArgumentNullException(
"field",
"field cannot be null.");
91 JToken child = jtok[field];
92 if (
null == child)
return null;
94 if (child.Type == JTokenType.Boolean)
106 internal static void writeIfNotNullOrEmpty(JsonTextWriter writer,
string key,
string value)
108 if (
string.IsNullOrEmpty(value))
return;
109 writer.WritePropertyName(key);
110 writer.WriteValue(value);
117 private static void ensureValidFieldName(
string name)
119 if (
string.IsNullOrEmpty(name))
throw new ArgumentNullException(
"name");
static ? bool GetOptionalBoolean(JToken jtok, string field)
Retrieves the optional boolean property value for the given property name from the given JSON object.
static string GetRequiredString(JToken jtok, string field)
Retrieves the required string property value for the given property name from the given JSON object.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
static string GetOptionalString(JToken jtok, string field)
Retrieves the optional string property value for the given property name from the given JSON object.
static int GetRequiredInteger(JToken jtok, string field)
Retrieves the required int property value for the given property name from the given JSON object.