Ejemplo n.º 1
0
        public string[] DeserializeObject(string schemeName, byte[] bytes, out JsonObjectScheme scheme)
        {
            scheme = GetObjectScheme(schemeName, bytes);
            if (scheme == null)
            {
                return(null);
            }
            int startIndex = 0;

            return(DeserializeObject(bytes, ref startIndex, scheme.Names));
        }
Ejemplo n.º 2
0
        protected JsonObjectScheme GetObjectSchemeCore(byte[] bytes, int startIndex)
        {
            int index = startIndex;
            List <JsonPropertyInfo> items = new List <JsonPropertyInfo>();
            List <string>           props = new List <string>();

            if (!FindChar(bytes, '{', ref index))
            {
                return(null);
            }
            int propIndex = 0;

            index++;
            while (bytes[index] != '}')
            {
                int nameStart = index;
                if (!FindChar(bytes, ':', ref index))
                {
                    return(null);
                }
                JsonPropertyInfo info = new JsonPropertyInfo();
                info.Length = index - nameStart;
                info.Index  = propIndex;
                propIndex++;
                if (bytes[nameStart] == '"' || bytes[nameStart] == '\'')
                {
                    info.HasQuotes = true;
                    info.Name      = ByteArray2String(bytes, nameStart + 1, info.Length - 2);
                }
                else
                {
                    info.Name = ByteArray2String(bytes, nameStart, info.Length);
                }
                items.Add(info);
                index++;
                FindChar(bytes, '}', ',', ref index);
                if (bytes[index] == '}')
                {
                    break;
                }
                index++; // skip ,
            }
            JsonObjectScheme res = new JsonObjectScheme();

            res.Fields = items;
            res.Names  = items.Select(i => i.Name).ToArray();
            return(res);
        }
Ejemplo n.º 3
0
        public JsonObjectScheme GetObjectScheme(string schemeName, byte[] bytes)
        {
            if (bytes.Length <= 2)
            {
                return(JsonObjectScheme.Empty);
            }
            Dictionary <string, JsonObjectScheme> dic = null;

            lock (Schemes) {
                if (!Schemes.TryGetValue(schemeName, out dic))
                {
                    dic = new Dictionary <string, JsonObjectScheme>();
                    Schemes.Add(schemeName, dic);
                }
            }
            string firstField = GetFirstField(bytes);

            if (firstField == null)
            {
                return(null);
            }

            JsonObjectScheme res = null;

            lock (dic) {
                if (dic.TryGetValue(firstField, out res))
                {
                    return(res);
                }
                res = GetObjectSchemeCore(bytes, 0);
                if (res == null)
                {
                    return(null);
                }
                res.Name = schemeName;
                dic.Add(firstField, res);
            }
            return(res);
        }