Exemple #1
0
        /// <summary>
        /// IList 转换成 JavascriptArray
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        private Newtonsoft.Json.JavaScriptArray GetArray <T>(IList list) where T : Entry
        {
            Newtonsoft.Json.JavaScriptArray jsonArray = new Newtonsoft.Json.JavaScriptArray();

            if (!(null == list || list.Count == 0))
            {
                foreach (object obj in list)
                {
                    if (obj != null)
                    {
                        T t = obj as T;
                        jsonArray.Add(t);
                    }
                }
            }

            return(jsonArray);
        }
        private JavaScriptArray PopulateJavaScriptArray(JsonReader reader)
        {
            JavaScriptArray jsArray = new JavaScriptArray();

            while (reader.Read())
            {
                switch (reader.TokenType)
                {
                case JsonToken.EndArray:
                    return(jsArray);

                case JsonToken.Comment:
                    break;

                default:
                    object value = GetObject(reader, null);

                    jsArray.Add(value);
                    break;
                }
            }

            throw new JsonSerializationException("Unexpected end while deserializing array.");
        }