TopSimplifyJsonParser.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using FastJSON;
  2. using System;
  3. using System.Collections;
  4. namespace Top.Api.Parser
  5. {
  6. public class TopSimplifyJsonParser<T> : TopJsonParser<T> where T : TopResponse
  7. {
  8. public override T Parse(string body)
  9. {
  10. T rsp = null;
  11. IDictionary rootJson = JSON.Parse(body) as IDictionary;
  12. if (rootJson != null)
  13. {
  14. IDictionary data = rootJson;
  15. if (rootJson.Contains(Constants.ERROR_RESPONSE))
  16. {
  17. data = rootJson[Constants.ERROR_RESPONSE] as IDictionary;
  18. }
  19. if (data != null)
  20. {
  21. ITopReader reader = new TopSimplifyJsonReader(data);
  22. rsp = (T)FromJson(reader, typeof(T));
  23. }
  24. }
  25. if (rsp == null)
  26. {
  27. rsp = Activator.CreateInstance<T>();
  28. }
  29. if (rsp != null)
  30. {
  31. rsp.Body = body;
  32. }
  33. return rsp;
  34. }
  35. }
  36. }