#1 2025-07-17 06:39:11

bigheart
Member
Registered: 2014-08-01
Posts: 54

How to get unescaped json string from IDocList

Hi all!

When make json string using IDocList, the escape char is added to the result.

var
  LDocList: IDocList;
begin
  LDocList := DocList('[]');
  LDocList.Append('{"text": "test"}');
  ShowMessage(LDocList.Json);  //shows '["{\"text\": \"test\"}"]'

How to get unescaped json string with IDocList?

Offline

#2 2025-07-17 14:41:54

flydev
Member
From: France
Registered: 2020-11-27
Posts: 96
Website

Re: How to get unescaped json string from IDocList

Hi, because it's a string, it's appending a string item to a json array.
Use IDocDict to add an object:

LDocList.AppendDoc(DocDict(['text', 'test']));

or you can serialize directly:

LDocList.Json := '[{"text": "test"},{"text": "test2"}]'; // don't make sense: `DocList('[{"text": "test"}]');`

when the array (Len) is not empty, you can assign an object directly to it using:

LDocList.O[1] := DocDict(['text', 'test2 is now test3']);

Last edited by flydev (2025-07-17 14:45:43)

Offline

Board footer

Powered by FluxBB