Esempio n. 1
0
        public T Parse(string body, Type type)
        {
            T rsp = null;

            IDictionary json = JSON.Parse(body) as IDictionary;

            if (json != null)
            {
                IDictionary data = json;

                if (data != null)
                {
                    ITopReader reader = new TopSimplifyJsonReader(data);
                    rsp = (T)FromJson(reader, type);
                }
            }

            if (rsp == null)
            {
                rsp = Activator.CreateInstance(type) as T;
            }

            if (rsp != null)
            {
                rsp.Body = body;
            }

            return(rsp);
        }
        public override T Parse(string body)
        {
            T rsp = null;

            IDictionary rootJson = JSON.Parse(body) as IDictionary;

            if (rootJson != null)
            {
                IDictionary data = rootJson;
                if (rootJson.Contains(Constants.ERROR_RESPONSE))
                {
                    data = rootJson[Constants.ERROR_RESPONSE] as IDictionary;
                }

                if (data != null)
                {
                    ITopReader reader = new TopSimplifyJsonReader(data);
                    rsp = (T)FromJson(reader, typeof(T));
                }
            }

            if (rsp == null)
            {
                rsp = Activator.CreateInstance <T>();
            }

            if (rsp != null)
            {
                rsp.Body = body;
            }

            return(rsp);
        }