使用Delphi从网站获取JSON数据 [英] Getting JSON data from a website using Delphi

查看:571
本文介绍了使用Delphi从网站获取JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这个网站 http://www.ingress.com/intel



要访问该网站,我们必须使用用户名和密码进行登录。



一旦访问,该网站将使用JSON作为其数据。 / p>

我是这个JSON的新东西。



任何人都可以给出一个一般的例子,如何从一个网站使用Delphi?



我正在使用Delphi 7。



谢谢。 b $ b

解决方案

这两个问题。


  1. 如何从HTTP服务器获取文件

  2. 如何解析JSON字符串

对于第一个问题,有很多图书馆,其中一些:


  1. Internet Direct aka Indy Sockets(与Delphi一起发行, http://www.indyproject.org/

  2. 互联网组件套件还有ICS http://www.overbyte.be

  3. ararat Synapse http://synapse.ararat.cz/

  4. 来自JEDI VCL的UrlListGrabber http://jvcl.sf.net

  5. Windows InternetReadFile http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103.aspx

  6. .. 。还有很多。

例如,这是从互联网获取文件的示例: http:// synapse.ararat.cz/doku.php/public:howto:httpgetpage



或者另一个lib的演示(实际上每个lib都有它们,从HTTP加载文件是所以常见的任务...):








对于JSON解析器,在从网络下载内容之后,这是一个较窄的选择:JSON是一个相对较新的趋势,许多JSON解析器大量使用Delphi 2009+的功能
我个人认为最好尝试使用mORMot项目中的JSON解析器。
该项目也有HTTP层,所以也许你可以使用他们的代码通过HTTP读取文件。



有例子或解析JSON字符串: p>



更多信息在 http://synopse.info/ http:/ /blog.synopse.info/tag/JSON



他们还有响应社区的论坛。



SuperObject,虽然最初建立在泛型(实际工作以来,Delphi 2010)),也具有Delphi 7的兼容性,尽管其一些功能不起作用。请参见 http://code.google.com/p/superobject/wiki/first_steps



您总是可以在 http:// www.torry.net


There is this website http://www.ingress.com/intel

To access the website, we must login using username and password.

Once accessed, the site uses JSON for its data.

I am new to this JSON thing.

Anyone can give a general example how to get JSON data from a website using Delphi?

I am using Delphi 7 by the way.

Thanks.

解决方案

Those are two questions.

  1. how to get file from HTTP server
  2. how to parse JSON string

For 1st question there are a lot of libraries, some of those:

  1. Internet Direct aka Indy Sockets (distributed with Delphi and http://www.indyproject.org/)
  2. Internet Components Suite aka ICS http://www.overbyte.be
  3. ararat Synapse http://synapse.ararat.cz/
  4. UrlListGrabber from JEDI VCL http://jvcl.sf.net
  5. Windows InternetReadFile http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103.aspx
  6. ...and many many more.

For example this is a sample of getting file from internet: http://synapse.ararat.cz/doku.php/public:howto:httpgetpage

Or another lib's demos (actually every lib has them, loading file from HTTP is so common task...):


As for JSON parsers, after you downloaded content from net, that is a narrower choice: JSON is a relatively recent trend and many JSON parsers heavily use features of Delphi 2009+
Personally i think you'd better try to use JSON parser from mORMot project. That project also has HTTP layer so perhaps you can use their code to read file over HTTP as well.

There are examples or parsing JSON string:

More info at http://synopse.info/ and http://blog.synopse.info/tag/JSON

They also have forum with responsive community.

SuperObject, while originally built around generics (practically working since Delphi 2010), also has Delphi 7 compatibility, though some of its features would not work. See http://code.google.com/p/superobject/wiki/first_steps

And you always can search for more libraries on http://www.torry.net

这篇关于使用Delphi从网站获取JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆