Closed leeonsoft closed 1 year ago
Could you provide a small example?
var json:TMcJsonItem; str:string; JsonObject:TJsonObject; begin try { TODO -oUser -cConsole Main : Insert code here } json:=TMcJsonItem.Create; JsonObject:=TJsonObject.Create; try json.add('topic').AsString:='test'; json.add('content').AsString:='{"name":"111"}'; Str:= json.ToString(false); writeln('mcJson:'+str); JsonObject.S['topic']:='test'; JsonObject.S['content']:='{"name":"111"}'; Str:= JsonObject.ToJSON(); writeln('JsonObject:'+str); Readln; finally json.Free; JsonObject.Free; end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
If you provide an escaped string representing a JSON object it will work. There is an example in Test11:
'{"k":"{\"key\":\"value\"}"}'
McJSON doesn't do the escapes for you.
However, the correct thing would be to throw an exception, since it is not being managed automatically.
I'll improve it to automatically manage this or throw an exception.
Thanks.
I need mcjson to help me generate the correct json string so that other programs can parse it
You can write a simple function in order to escape double quotes:
json.add('content').AsString:= MyEscapeDoubleQuotes('{"name":"111"}');
When value is a json string, tostring does not handle escaping