Building a JSON object in TMS WEB Core with arrays

Hi

Are there any examples of building JSON objects in TMS WebCore ?
I have successfully used TJSON, TJSONObject + TJSON Array to parse responses from REST services but when building request with more complicated structure than just single name value structure I get empty arrays.

Target to create is something like this :

{"Array1" : [{"key1" : "Value1"}, {"key2": "value2"}]}

Regards
Eirik

Just after I reqgistered this I found Bruno's response on this :

Solved it for me :slight_smile:

procedure TForm1.WebButtonParseClick(Sender: TObject);
var
  lJSONObject : TJSONObject;
  lArrayObject : TJSONObject;
  lJSONArray : TJSONArray;
begin
  lJSONObject := TJSONObject.Create;
  lJSONObject.AddPair('key1', 'value1');
  lJSONObject.AddPair('key2', 'value2');

  lJSONArray := TJSONArray.Create;
  lJSONArray.Add(lJSONObject);

  lArrayObject := TJSONObject.Create;
  lArrayObject.AddPair('Array1', lJSONArray);
  WebMemoLog.Lines.Add(LArrayObject.ToString);

  lArrayObject.Free;
  lJSONArray.Free;
  lJSONObject.Free;
end;

Regards
Eirik

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.