Esempio n. 1
0
        protected static JsonElement?GetTokenIndex(JsonElement t, bool errorWhenNoMatch, int index)
        {
            if (t.ValueKind == JsonValueKind.Array)
            {
                if (t.GetArrayLength() <= index)
                {
                    if (errorWhenNoMatch)
                    {
                        throw new JsonException($"Index {index} outside the bounds of JArray.");
                    }

                    return(null);
                }

                return(t[index]);
            }
            else
            {
                if (errorWhenNoMatch)
                {
                    throw new JsonException($"Index {index} not valid on {t.GetType().Name}.");
                }

                return(null);
            }
        }
Esempio n. 2
0
 public static bool TryGetFirstFromArray(this JsonElement src, out JsonElement?element)
 {
     element = null;
     if (src.ValueKind == JsonValueKind.Array && src.GetArrayLength() > 0)
     {
         if (src.EnumerateArray().MoveNext())
         {
             element = src.EnumerateArray().Current;
             return(true);
         }
     }
     return(false);
 }