Getting JSON data from a website using Delphi [clo

2019-02-11 13:13发布

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.

2条回答
狗以群分
2楼-- · 2019-02-11 13:36

I suspect it will be pretty difficult to log in this specific website from a Delphi application.

You will need to log via a Google account, and handle cookies as expected.

Therefore, I'm afraid you won't be able to use any direct Indy / Synapse / ICS / WinINet library to access the data.

You will probably need to embed a full browser within the application, then access to the content from the JavaScript point of view, remoting the browser from your application.

Take a look at those components:

  • TWebBrowser (i.e. Internet Explorer) as available in Delphi;
  • Delphi Chromium.

Then you will have to parse the JSON content. But you must first ensure that you can login the application!

查看更多
小情绪 Triste *
3楼-- · 2019-02-11 13:50

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

查看更多
登录 后发表回答