-2

I am complete blank about JSON but I would like to be able to read some data from the URL http://stokercloud.dk/dev/getdriftjson.php?mac=oz8hp and be able to store them im a DB. But I don't know where to start, so I thought I would ask here for hints and maybe some links to samples that I might learn from I know that the output might look confusing, but I have a list of what each item is.

  • the file is runtime data from my pelletburner
OZ8HP
  • 1,443
  • 4
  • 31
  • 61
  • 2
    We don't do lists of hints, and a request for links to samples and tutorials is clearly stated as being off0-topic in the [help/on-topic]. (They fall under the "tool, library, or favorite off-site resource".) We also don't go somewhere else to see what the content is that you're discussing. There are many posts here about JSON (including many about Delphi and JSON). Please do some research first, and then when you have a **specific** question you can explain the problem here, include the *relevant parts* of your code that are causing you difficulty, and ask that **specific** question. – Ken White Jun 15 '14 at 14:52
  • 1
    Start at [ECMA-404/The JSON Data Interchange Format](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf) – Sir Rufo Jun 15 '14 at 17:11
  • 1
    Then I am very sorry for asking - will newer do that again. – OZ8HP Jun 15 '14 at 17:31
  • @SirRufo - Really! I think he needs a two sentence explanation that JSON is a text format for interchange of data and there is a library in virtually any language he cares to use. Don't send him to a big longer standards library to waste his time. – Toby Allen Jun 15 '14 at 20:23
  • @toby websearch yields that information – David Heffernan Jun 16 '14 at 06:19

3 Answers3

16

The JSON specification is the first page to read. The standard is so simple it is easy to understand it from this page.

I found a wider tutorial, with illustrations and more resources. Nice to see.

JSON explained

Here is the conclusion of this web page:

  • JSON is a open,text based, light-weight data interchange format specified as RFC4627, came to the developer world in 2005 and it's popularity is increased rapidly.
  • JSON uses Object and Array as data structures and strings, number, true, false and null as values. Objects and arrays can be nested recursively.
  • Most (if not all) modern programming languages can be used to work with JSON.
  • NoSQL databases, which are evolved to get rid of the bottlenecks of the Relational Databases, are using JSON to store data.
  • JSON gives developers a power to choose between XML and JSON leading to more flexibility.
  • Besides NoSQL, AJAX, Package Management, and integration of APIs to the web application are the major areas where JSON is being used extensively.

IMHO the main point with JSON is that it contains documents, or arrays of documents. There is less data types than with Delphi (e.g. no official date/time, and just one numeric type). It is an exchange format, which is widely used now, and, from my own experiment, easier to work with than XML, from both human and computer sides.

In Delphi, you have several libraries around, mainly:

About performance, you can take a look at our blog article. DBXJSON (and the official JSON unit of Delphi) is by far the slowest, and somewhat difficult to work with. Some methods for easy access to the JSON document content are missing. Other libraries are much easier to work with. Our version shipped with mORMot is very fast, as is dwsJSON. SuperObject is slower than those, especially for huge content, and XSuperObject is slow (but cross-platform). Our SynCrossPlatformJSON unit is also cross-platform, very fast, and has a variant-based document access.

Some code using mORMot library:

uses
  SynCrtSock,
  SynCommons;

procedure test;
var json: RawUTF8;
    jsondata: TDocVariantData;
    i: integer;
begin
  json := TWinHttp.Get('http://stokercloud.dk/dev/getdriftjson.php?mac=oz8hp');
  jsondata := DocVariantData(_json(json).jsondata)^;
  for i := 0 to jsondata.Count-1 do
    writeln(jsondata.Values[i]); // here all items are converted back to JSON and written
end;
Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159
1
  1. To learn JSON (JavaScript Object Notation), you'd read JSON on Wikipedia.
  2. To download data from url, you can use TIdHttp, which is an Http client of Indy framework.
  3. To parse JSON, I'd suggest use superobject. It includes great examples in demos directory.
stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94
  • 1
    the superobject wiki page is simply blank https://code.google.com/p/superobject/w/list – G-Man Jun 15 '14 at 15:47
  • @Gaetano Thanks for correcting me. Examples are included in download package. `superobject` works very stable in many of my projects. – stanleyxu2005 Jun 15 '14 at 15:55
  • **DO NOT** download the 1.2.4 source ZIP file, but go to the source tab to download up-to-date source. See my notes at [SuperObject cannot handle null string](http://stackoverflow.com/questions/18445280/superobject-cannot-handle-null-string) – Jan Doggen Jun 15 '14 at 20:17
  • I'm still wondering why SuperObject claims to be Linux/FPC compatible in its project page, whereas the current source code currently is not. – Arnaud Bouchez Jun 16 '14 at 08:32
  • @ArnaudBouchez A new iteration of SuperObject called `XSuperObject` introduces multi-platform ability. However, I'm finding all kinds of bugs in it. – Jerry Dodge Dec 17 '14 at 18:29
  • @JerryDodge yes xsuperobject is cross platform but slow. See http://stackoverflow.com/a/24232359/458259 – Arnaud Bouchez Dec 18 '14 at 12:57
0

JSON is an interchange form for sending data between anything that needs to have data sent to it. Its simplicity is its strength.

The text is valid javascript and so can be interpreted by any javascript compiler, but is now so popular that virtually every language now has a json parser built in or as a library ( see http://json.org/ scroll down to the bottom).

Basically JSON is a very simple structured text. If you google JSON Library Delphi you should get some solutions or for any other language you want to use.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124