Delphi uses Superobject to implement HTTP remote invocation of JSONRPC good

Source: Internet
Author: User

[Delphi]View PlainCopy
  1. Procedure TFORM5.  Button4click (Sender:tobject);
  2. Var
  3. O, Item:isuperobject;
  4. Strm:tstringstream;
  5. Result: string;
  6. Ctx:tsuperrtticontext;
  7. Student:tstudent;
  8. Begin
  9. //can refer to Superobject's readme.html
  10. //json Demo Https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29
  11. //{"JSONRPC": "2.0", "method": "Fuck", "params": ["hehe", 32,4], "id": "1433813750019"}
  12. //O: = So (' {"JSONRPC": "2.0", "method": "Fuck", "params": ["hehe", 32,4], "id": "1433813750019"} ');
  13. //O: = So (' {"JSONRPC": "2.0", "method": Fuck, "params": ["hehe", 32,4]} ');
  14. O: = SO (
  15. ' {"JSONRPC": "2.0", "method": "Fuck", "params": ["hehe", 32,4], "id": "12"} ');
  16. STRM: = Tstringstream. Create (O.  asstring);
  17. Try
  18. IdHTTP1. Request.  ContentType: = ' Application/json ';
  19. Result: = IdHTTP1.  Post (' http://10.0.0.107/json_server/server.php ', STRM);
  20. Memo1. Lines.  ADD (result);
  21. O: = SO (result);
  22. Memo1. Lines. ADD (O. Asobject.  s[' result ');
  23. O: = SO (
  24. ' {"JSONRPC": "2.0", "Method": "Getstudent", "params": [{"id": 1, "name": "Name", "Age": 123}], "id": "1433813750240"} '  );
  25. STRM: = Tstringstream. Create (O.  asstring);
  26. Result: = IdHTTP1.  Post (' http://10.0.0.107/json_server/server.php ', STRM);
  27. Memo1. Lines.  ADD (result);
  28. O: = SO (result);
  29. Result: = O. Asobject.  s[' result ';
  30. Memo1. Lines.  ADD (result);
  31. CTX: = Tsuperrtticontext.  Create;
  32. Try
  33. //JSON conversion to object
  34. Student: = CTX.  Astype<tstudent> (SO (result));
  35. ShowMessage (student. Name);
  36. //Object converted to JSON
  37. O: = CTX.  Asjson<tstudent> (student);
  38. ShowMessage (O.  asstring);
  39. finally
  40. //CTX.  Free;
  41. end;
  42. O: = SO (
  43. ' {' Jsonrpc ': ' 2.0 ', ' method ': ' getstudents ', ' params ': [' xxx '], ' id ': ' 1433814568751 '} ';
  44. STRM: = Tstringstream. Create (O.  asstring);
  45. Result: = IdHTTP1.  Post (' http://10.0.0.107/json_server/server.php ', STRM);
  46. Memo1. Lines.  ADD (result);
  47. O: = SO (result);
  48. Memo1. Lines. ADD (O. Asobject.  s[' result ');
  49. For item in o[' result ') do
  50. begin
  51. Student: = CTX.  Astype<tstudent> (item);
  52. ShowMessage (student. Name);
  53. //ShowMessage (item.  asstring);
  54. end;
  55. finally
  56. STRM.  Free;
  57. end;
  58. End

http://blog.csdn.net/earbao/article/details/46423167

Delphi uses Superobject to implement HTTP remote invocation of JSONRPC good

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.