/// <summary> /// JsonArray constructor by a given JArray type of object. /// </summary> /// <param name="jArray">JArray object</param> internal JsonArray(JArray jArray) { foreach (JToken tk in jArray.Children()) { object o = JsonNet.ReturnValidObject(tk); jsonArray.Add(o); } }
/// <summary> /// Parses a json formated string. It will return JsonObjects /// or other match that the parser can do from the input. /// Error will be thrown if parser fails. /// </summary> /// <param name="jsonString">String with a json format</param> /// <returns name="object">Object returned by the parser</returns> /// <search> /// json, parse, jsonstring /// </search> public static object String(string jsonString) { if (jsonString == null) { throw new ArgumentNullException("jsonString"); } JToken parsed = JToken.Parse(jsonString); return(JsonNet.ReturnValidObject(parsed)); }
/// <summary> /// JsonObject constructor by a given JObject element. /// </summary> /// <param name="jObject">JObject element.</param> /// <param name="nesting">Apply nesting behaviour if key input is a single string concatenated by /// dots, representing the desired nested structure</param> internal JsonObject(JObject jObject, bool nesting = false) { List <string> keys = new List <string>(); List <object> values = new List <object>(); foreach (JProperty p in jObject.Properties()) { keys.Add(p.Name); //Replacing null values to "null" string. When parsing XML, some items might be null and cause an exception. //TODO: Find a better way of handling nulls. object value = (p.Value.ToObject <object>() == null) ? "null" : JsonNet.ReturnValidObject(p.Value); values.Add(value); } List <KeyValuePair <string, object> > pair = keys.Zip(values, (k, v) => new KeyValuePair <string, object>(k, v)).ToList(); pair.ForEach(p => AddInternal(this, p.Key, p.Value, JsonOption.None)); }