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.
- how to get file from HTTP server
- how to parse JSON string
For 1st question there are a lot of libraries, some of those:
- Internet Direct aka Indy Sockets (distributed with Delphi and http://www.indyproject.org/)
- Internet Components Suite aka ICS http://www.overbyte.be
- ararat Synapse http://synapse.ararat.cz/
- UrlListGrabber from JEDI VCL http://jvcl.sf.net
- Windows
InternetReadFile
http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103.aspx
- ...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...):
- http://jvcl.svn.sourceforge.net/viewvc/jvcl/trunk/jvcl/examples/JvProgramVersionCheck/
- http://jvcl.svn.sourceforge.net/viewvc/jvcl/trunk/jvcl/examples/JvUrlListGrabber/
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:
- http://blog.synopse.info/post/2012/05/03/Custom-JSON-serialization-of-records
- http://blog.synopse.info/post/2012/04/13/Custom-JSON-serialization-of-any-class
- http://blog.synopse.info/post/2012/04/12/Custom-JSON-serialization-of-any-dynamic-array-content
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
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!