示例#1
0
        /// <summary>
        /// 字符串扩展
        /// </summary>
        /// <param name="stringList"></param>
        /// <param name="response"></param>
        public static void ShowAsJson(this IList<string> stringList, HttpResponse response)
        {
            response.WriteJsonBegin();
            response.WriteJosnWithNoValue("values");
            response.WriteArrayBegin();

            int i = 1;
            foreach (var s in stringList)
            {
                if (string.IsNullOrEmpty(s))
                    continue;

                response.WriteJsonBegin();

                response.WriteJsonWithValue("id", i++.ToString(), false);
                response.WriteJsonWithValue("value", s.ToString(), true);

                response.WriteJsonEnd(stringList.Last() == s);

            }
            response.WriteArrayEnd();
            response.WriteJsonEnd(true);
        }