public static object DecodeMsg(String msg) { IDictionary dict = TopUtils.ParseJson(msg); if (dict != null && dict.Count > 0) { IEnumerator em = dict.Keys.GetEnumerator(); em.MoveNext(); IDictionary data = dict[em.Current] as IDictionary; if (data != null) { TopJsonParser tjp = new TopJsonParser(); ITopReader reader = new TopJsonReader(data); //if (dict.Contains(NOTIFY_ITEM)) //{ // return tjp.FromJson(reader, typeof(NotifyItem)); //} if (dict.Contains(NOTIFY_TRADE)) { return(tjp.FromJson(reader, typeof(NotifyTrade))); } //else if (dict.Contains(NOTIFY_REFUND)) //{ // return tjp.FromJson(reader, typeof(NotifyRefund)); //} } } return(null); }
public T Parse <T>(string body) where T : AliyunResponse { T rsp = null; IDictionary json = JSON.Parse(body) as IDictionary; if (json != null) { ITopReader reader = new TopJsonReader(json); rsp = (T)FromJson(reader, typeof(T)); } if (rsp == null) { rsp = Activator.CreateInstance <T>(); } if (rsp != null) { rsp.Body = body; } return(rsp); }
public T Parse(string body, Type type) { T rsp = null; IDictionary json = JSON.Parse(body) as IDictionary; if (json != null) { IDictionary data = null; // 忽略根节点的名称 foreach (object key in json.Keys) { data = json[key] as IDictionary; break; } if (data != null) { ITopReader reader = new TopJsonReader(data); rsp = (T)FromJson(reader, type); } } if (rsp == null) { rsp = Activator.CreateInstance(type) as T; } if (rsp != null) { rsp.Body = body; } return(rsp); }