Search code examples
jsondelphiindy10

Indy 10 server : How to send JSON response?


I am looking for a simple code example, using Data.DBXJSON's TJSONObject to build a response and return it in AResponseInfo.ContentText.

Google does not seem to be my friend today :-(


Solution

  • The answer is in Embarcadero's documentation. There is an example showing how to create and parse JSON strings. TJSONObject has a ToString() method, eg:

    var
      JSON: TJSONObject;
    begin
      ...
      JSON := TJSONObject.Create;
      try
        // populate JSON as needed...
        AResponseInfo.ContentText := JSON.ToString;
      finally
        JSON.Free;
      end;
      ...
    end;