QimenCloudSimplifyJsonParser.cs 1.1 KB

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