Ejemplo n.º 1
0
        /// <summary>
        /// 数组解析
        /// </summary>
        /// <param name="jsonDeSerializer">Json解析器</param>
        /// <param name="array">目标数据</param>
        /// <returns>数据数量,-1表示失败</returns>
        internal static int ArrayIndex(JsonDeSerializer jsonDeSerializer, ref T[] array)
        {
            switch (jsonDeSerializer.SearchArray(ref array))
            {
            case 0:
                array = new T[jsonDeSerializer.Config.NewArraySize];
                int index = 0;
                do
                {
                    if (index != array.Length)
                    {
                        DeSerialize(jsonDeSerializer, ref array[index]);
                        if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                        {
                            return(-1);
                        }
                        ++index;
                    }
                    else
                    {
                        T value = default(T);
                        DeSerialize(jsonDeSerializer, ref value);
                        if (jsonDeSerializer.DeSerializeState != DeSerializeState.Success)
                        {
                            return(-1);
                        }
                        array          = array.copyNew(index == 0 ? jsonDeSerializer.Config.NewArraySize : (index << 1));
                        array[index++] = value;
                    }
                }while (jsonDeSerializer.IsNextArrayValue());
                return(jsonDeSerializer.DeSerializeState == DeSerializeState.Success ? index : -1);

            case 1: return(0);

            default: return(-1);
            }
        }