Parsing

<< Click to Display Table of Contents >>

Navigation:  JSON >

Parsing

There are several ways of creating JSON object from string:

 

1.  Simply assign JSON string to THtJSON variable

 

    var E: THtJSON := '{"some": "test"}';
    ShowMessage(E.S['some']);

 

2. Implicit casting

 

    var E := THtJSON('{"some": "test"}');

 

3. Parse method

 

    var E: THtJSON;
    E.Parse('{"some": "test"}');

 

4. Create method

    var E := THtJSON.Create('{"some": "test"}');
 

 

5. LoadfromFile method:

 

    var E: THtJSON;
    E.LoadfromFile(FileName);

 

6. JSON() function.

Difference between Parse and Create is that Parse returns read-only object.
 

Simple values can be extracted from JSON without use of variables. Example:

 

 sum := JSON(str).Find('result.orders[delivered=true].sum()');

 

To create a new empty  object or array use Create('{}') or Create('[]')