Json.Serialization.JsonFormatter.GetSubObject C# (CSharp) Method

GetSubObject() private method

Returns next sub-object string
private GetSubObject ( string s, int &pos ) : string
s string string to be searched
pos int start position
return string
        private string GetSubObject(string s, ref int pos)
        {
            int nb = 0;
            int ns = s.IndexOf('{', pos);
            int ne = ns;
            do
            {
                ne = s.IndexOfAny(new char[] { '{', '}' }, ne);
                if (ne == -1) return string.Empty;
                if (s[ne] == '{') nb++;
                if (s[ne] == '}') nb--;
            } while (nb > 0);

            pos = ne;
            return s.Substring(ns, ne - ns);
        }