//Indexers and accesors public JsonNode this[string key] { get { if (this is JsonObjectCollection JOC) { return(JOC[key]); } else { return(null); } } set { JsonObjectCollection JOC = this as JsonObjectCollection; { JOC[key] = value; } } }
private static JsonNode ParseJsonPart(string jsonPart) { JsonNode jsonPartValue = null; if (jsonPart.Length == 0) { return(jsonPartValue); } switch (jsonPart[0]) { case JsonNode.CHAR_CURLY_OPEN: { JsonObjectCollection JsonObjectCollection = new JsonObjectCollection(); List <string> splittedParts = SplitJsonParts(jsonPart.Substring(1, jsonPart.Length - 2)); string[] keyValueParts = new string[2]; foreach (string keyValuePart in splittedParts) { keyValueParts = SplitKeyValuePart(keyValuePart); if (keyValueParts[0] != null) { JsonObjectCollection[JsonNode.UnescapeString(keyValueParts[0])] = ParseJsonPart(keyValueParts[1]); } } jsonPartValue = JsonObjectCollection; } break; case JsonNode.CHAR_SQUARED_OPEN: { JsonArrayCollection JsonArrayCollection = new JsonArrayCollection(); List <string> splittedParts = SplitJsonParts(jsonPart.Substring(1, jsonPart.Length - 2)); foreach (string part in splittedParts) { if (part.Length > 0) { JsonArrayCollection.Add(ParseJsonPart(part)); } } jsonPartValue = JsonArrayCollection; } break; case JsonNode.CHAR_QUOTE: { jsonPartValue = new JsonBasic(JsonNode.UnescapeString(jsonPart.Substring(1, jsonPart.Length - 2))); } break; case JsonNode.CHAR_FALSE_LITERAL: //false { jsonPartValue = new JsonBasic(false); } break; case JsonNode.CHAR_TRUE_LITERAL: //true { jsonPartValue = new JsonBasic(true); } break; case JsonNode.CHAR_NULL_LITERAL: //null { jsonPartValue = null; } break; default: //it must be a number or it will fail { if (long.TryParse(jsonPart, NumberStyles.Any, CultureInfo.InvariantCulture, out long longValue)) { if (longValue > int.MaxValue || longValue < int.MinValue) { jsonPartValue = new JsonBasic(longValue); } else { jsonPartValue = new JsonBasic((int)longValue); } } else { if (decimal.TryParse(jsonPart, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal decimalValue)) { jsonPartValue = new JsonBasic(decimalValue); } } } break; } return(jsonPartValue); }