如何发送/接收JSON? [英] How to send/receive JSON?
问题描述
我已经google了,很清楚如何对JSON数据进行编码和解码,但我很新,我不知道如何与给定的URL进行通信并说这里有一些数据,请给我一些回来。
任何人都可以指出一个简单的工作代码示例?例如,只是传递用户名和密码作为JSON和接收一些答复...我想我应该使用 TIdHTTP
,但不知道如何使用JSON 。我有一个GET和一个POST界面。
+1到@DavidHeffernan,但我不明白谁可以通过我的请求传递打包的JSON数据或从响应。 En / de代码很好,但添加它作为参数让我陷入困境。
我真的很感激(链接到)一个小而完整的工作示例。
Btw,I只有XE2起始版,所以我没有datasnap。
对于通过HTTP的JSON进程,以下S / O问题:
http://stackoverflow.com/a/15948106/458259
如果您的问题是如何在Delphi中使用远程RESTful服务,您将找到答案。
但是如果要使用JSON和HTTP在Delphi应用程序之间进行通信,最简单的方法是在Delphi中实现RESTful Client-Server连接。
对于使用JSON的客户端 - 服务器传输和RESTful,请查看我们的开源 Synopse mORMot框架。它将为您完成所有的JSON序列化和RESTful路由。
它具有客户端服务器ORM(可能不是您需要的)。
而且还有一个使用两种模式的SOA框架:
您可以选择任一模式通过HTTP使用JSON通信。
请注意,由于不使用Pro / Entreprise / Architect版本的任何高级功能,mORMot预计将与Delphi XE2起始版配合使用,像DB.pas或DataSnap。并且它将允许您访问数据库,即使使用起始版。如果在入门手册中遗漏了某些问题,请随时在我们的论坛上报告问题。
A dumb question, I know. But I don't normally do web programming and have been asked to send some JSON data and receive some in return.
I googled and it is clear how to encode and decode the JSON data, but I am so new to this that I don't know how to communicate with the given URL and say "here's some data, please send me some back".
Can anyone point me at a simple working code example? For instance, just to pass user_name and password as JSON and to receive some reply ... I think I should be using TIdHTTP
, but am not sure how to use it with JSON. I have one GET and one POST interface.
+1 to @DavidHeffernan but I don't understand who to pass the packed JSON data with my request or to retrieve it from the response. En/de-code is fine, but adding it as parameters has me bogged down.
I really would appreciate a (link to a) small, but complete working example.
Btw, I only have XE2 starter edition, so I don't have datasnap.
For the JSON process via HTTP, take a look at the following S/O question: http://stackoverflow.com/a/15948106/458259
If your problem is about how to consume a remote RESTful service in Delphi, you will find it the answer.
But if you want to communicate between Delphi applications using JSON and HTTP, the easiest is to implemenent a RESTful Client-Server connection in Delphi.
For Client-Server transmission using JSON and RESTful, take a look at our Open Source Synopse mORMot framework. It will do all the JSON serialization and RESTful routing for you.
It features a Client-Server ORM (perhaps not what you need here).
But also a SOA framework using two modes:
You can chose either mode to use JSON communication over HTTP.
Note that mORMot is expected to work with Delphi XE2 starter edition, since it does not use any "advanced" feature of the Pro/Entreprise/Architect editions, like DB.pas or DataSnap. And it will allow you to access databases, even with a starter edition. In case of difficulties due to something missing in the Starter, please feel free to report the problem on our forum.
这篇关于如何发送/接收JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!