ShowCommentsHttp.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using LitJson;
  6. using UnityEngine;
  7. public class ShowCommentsHttp
  8. {
  9. public bool disable;
  10. private Action<object> succeedCallback;
  11. private Action failedCallback;
  12. public void Callback(JsonData data)
  13. {
  14. //Debug.Log(data.ToJson());
  15. if (disable)
  16. {
  17. return;
  18. }
  19. bool succeed = data.Inst_Object.ContainsKey("list");
  20. if (succeed == false)
  21. {
  22. if (failedCallback != null)
  23. failedCallback.Invoke();
  24. }
  25. else
  26. {
  27. List<ShowCommentData> commentDatas = new List<ShowCommentData>();
  28. JsonData listData = data["list"];
  29. for (int i = 0; i < listData.Count; i++)
  30. {
  31. //Debug.Log(listData[i].ToJson());
  32. ShowCommentData commentData = new ShowCommentData(listData[i]);
  33. commentDatas.Add(commentData);
  34. }
  35. //Debug.Log(commentDatas.Count);
  36. if (succeedCallback != null)
  37. succeedCallback.Invoke(commentDatas);
  38. }
  39. }
  40. public void Callback(string str)
  41. {
  42. Debug.Log(str);
  43. }
  44. public static void Test()
  45. {
  46. Get(0, 46, null, null);
  47. }
  48. public static void Get(int page, int showId, Action<object> succeedCallback, Action failedCallback)
  49. {
  50. ShowCommentsHttp http = new ShowCommentsHttp();
  51. http.succeedCallback = succeedCallback;
  52. http.failedCallback = failedCallback;
  53. URLRequestData requestData = new URLRequestData();
  54. requestData.Add("p", page);
  55. requestData.Add("s", showId);
  56. URLRequest.CreateURLRequest(true, HttpManager.GetShowCommentListURL, requestData,
  57. http.Callback, URLRequest.Method.POST);
  58. //URLRequest.CreateStrURLRequest(true, HttpManager.GetShowCommentListURL, requestData,
  59. // http.Callback, URLRequest.Method.POST);
  60. }
  61. }