示例#1
0
        private IEnumerable <object> ReadArrayValue(JsonReader jsonReader)
        {
            this.IncreaseRecursionDepth();
            List <object> list = new List <object>();

            jsonReader.ReadNext();
            while (jsonReader.NodeType != JsonNodeType.EndArray)
            {
                switch (jsonReader.NodeType)
                {
                case JsonNodeType.StartObject:
                {
                    list.Add(this.ReadObjectValue(jsonReader));
                    continue;
                }

                case JsonNodeType.StartArray:
                {
                    list.Add(this.ReadArrayValue(jsonReader));
                    continue;
                }

                case JsonNodeType.PrimitiveValue:
                {
                    list.Add(jsonReader.ReadPrimitiveValue());
                    continue;
                }
                }
                return(null);
            }
            jsonReader.ReadEndArray();
            this.DecreaseRecursionDepth();
            return(list);
        }
示例#2
0
        /// <summary>
        /// Read the json array from the reader.
        /// </summary>
        /// <param name="jsonReader">JsonReader instance.</param>
        /// <param name="inputContext">The input context with all the settings.</param>
        /// <param name="recursionDepth">The recursion depth to start with.</param>
        /// <returns>a list of json objects.</returns>
        private static IEnumerable <object> ReadArrayValue(JsonReader jsonReader, ODataInputContext inputContext, int recursionDepth)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(jsonReader != null, "jsonReader != null");
            Debug.Assert(jsonReader.NodeType == JsonNodeType.StartArray, "jsonReader.NodeType == JsonNodeType.StartArray");
            Debug.Assert(inputContext != null, "inputContext != null");

            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, inputContext.MessageReaderSettings.MessageQuotas.MaxNestingDepth);

            List <object> array = new List <object>();

            jsonReader.ReadNext();
            while (jsonReader.NodeType != JsonNodeType.EndArray)
            {
                switch (jsonReader.NodeType)
                {
                case JsonNodeType.PrimitiveValue:
                    array.Add(jsonReader.ReadPrimitiveValue());
                    break;

                case JsonNodeType.StartObject:
                    array.Add(ReadObjectValue(jsonReader, /*insideJsonObjectValue*/ false, inputContext, recursionDepth));
                    break;

                case JsonNodeType.StartArray:
                    array.Add(ReadArrayValue(jsonReader, inputContext, recursionDepth));
                    break;

                default:
                    Debug.Assert(false, "We should never have got here - the valid states in array are primitive value or object");
                    return(null);
                }
            }

            jsonReader.ReadEndArray();

            return(array);
        }
 private IEnumerable<object> ReadArrayValue(JsonReader jsonReader)
 {
     this.IncreaseRecursionDepth();
     List<object> list = new List<object>();
     jsonReader.ReadNext();
     while (jsonReader.NodeType != JsonNodeType.EndArray)
     {
         switch (jsonReader.NodeType)
         {
             case JsonNodeType.StartObject:
             {
                 list.Add(this.ReadObjectValue(jsonReader));
                 continue;
             }
             case JsonNodeType.StartArray:
             {
                 list.Add(this.ReadArrayValue(jsonReader));
                 continue;
             }
             case JsonNodeType.PrimitiveValue:
             {
                 list.Add(jsonReader.ReadPrimitiveValue());
                 continue;
             }
         }
         return null;
     }
     jsonReader.ReadEndArray();
     this.DecreaseRecursionDepth();
     return list;
 }
        /// <summary>
        /// Read the json array from the reader.
        /// </summary>
        /// <param name="jsonReader">JsonReader instance.</param>
        /// <returns>a list of json objects.</returns>
        private IEnumerable<object> ReadArrayValue(JsonReader jsonReader)
        {
            Debug.Assert(jsonReader != null, "jsonReader != null");
            Debug.Assert(jsonReader.NodeType == JsonNodeType.StartArray, "jsonReader.NodeType == JsonNodeType.StartArray");

            this.IncreaseRecursionDepth();

            List<object> array = new List<object>();
            jsonReader.ReadNext();
            while (jsonReader.NodeType != JsonNodeType.EndArray)
            {
                switch (jsonReader.NodeType)
                {
                    case JsonNodeType.PrimitiveValue:
                        array.Add(jsonReader.ReadPrimitiveValue());
                        break;
                    case JsonNodeType.StartObject:
                        array.Add(this.ReadObjectValue(jsonReader));
                        break;
                    case JsonNodeType.StartArray:
                        array.Add(this.ReadArrayValue(jsonReader));
                        break;
                    default:
                        Debug.Assert(false, "We should never have got here - the valid states in array are primitive value or object");
                        return null;
                }
            }

            jsonReader.ReadEndArray();
            this.DecreaseRecursionDepth();

            return array;
        }