Exemple #1
0
        /// <summary>
        /// 获取Post结果
        /// </summary>
        /// <typeparam name="TResponse"></typeparam>
        /// <typeparam name="TError"></typeparam>
        /// <param name="returnText"></param>
        /// <param name="converter"></param>
        /// <returns></returns>
        public static TResponse GetResult <TResponse, TError>(string returnText, IJsonConverter converter = null)
            where TError : BaseError <TError>, new()
        {
            JavaScriptSerializer js = new JavaScriptSerializer();

            TError errorEng = new TError();

            if (errorEng.Has(returnText))
            {
                //if (converter != null) returnText = converter.Convert(returnText);
                //可能发生错误
                //TError errorResult = js.Deserialize<TError>(returnText);
                TError errorResult = errorEng.ToJson(returnText);
                if (!errorResult.IsSuccess())
                {
                    //发生错误
                    throw new JsonResultException(
                              string.Format("Post请求发生错误!错误信息:{0}", errorResult));
                }
            }
            if (converter != null)
            {
                returnText = converter.Convert(returnText);
            }
            TResponse result = js.Deserialize <TResponse>(returnText);

            return(result);
        }
Exemple #2
0
        public static TResponse GetJson <TResponse, TError>(string url, Encoding encoding = null, IJsonConverter converter = null)
            where TError : BaseError <TError>, new()
        {
            string returnText = RequestUtility.HttpGet(url, encoding);

            JavaScriptSerializer js = new JavaScriptSerializer();
            TError errorEng         = new TError();

            if (errorEng.Has(returnText))
            {
                //可能发生错误
                TError errorResult = errorEng.ToJson(returnText);//js.Deserialize<TError>(returnText);
                if (!errorResult.IsSuccess())
                {
                    //发生错误
                    throw new JsonResultException(
                              string.Format("请求发生错误!错误代码信息:{0}", errorResult));
                }
            }

            if (null != converter)
            {
                returnText = converter.Convert(returnText);
            }

            TResponse result = js.Deserialize <TResponse>(returnText);

            return(result);
        }
Exemple #3
0
        // GET: api/Homes
        public string Get()
        {
            var homeList = _animalsManager.GetAllHomes();

            var result = _mapper.Map <IEnumerable <HomeViewModel> >(homeList);

            return(_jsonConverter.Convert(result));
        }
Exemple #4
0
        public static T To <T>(string json, IJsonConverter <T> converter)
        {
            Guarder.CheckNull(converter, "converter");
            var engine = new ParseEngine();
            var value  = engine.Parse(json);

            return(converter.Convert(value));
        }
        // GET: api/Test
        public string Get()
        {
            var catList = _animalsManager.GetAllCats();

            var result = _mapper.Map <IEnumerable <CatViewModel> >(catList);

            return(_jsonConverter.Convert(result));
        }
Exemple #6
0
        public void ProcessPictureQuery()
        {
            var json = GetPictureQueryItemJson();
            var picturesQueryJson  = _jsonConverter.Parse(json.Result);
            var picturesQueryItems = _jsonConverter.Convert(picturesQueryJson);

            mPictureQueryItems = _pictureTransfer.GetPictures(picturesQueryItems).Result;
        }