GithubHelp home page GithubHelp logo

Comments (5)

hydrobyte avatar hydrobyte commented on July 17, 2024

Could you provide a small example?

from mcjson.

leeonsoft avatar leeonsoft commented on July 17, 2024

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.

QQ图片20220808180252

from mcjson.

hydrobyte avatar hydrobyte commented on July 17, 2024

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.

from mcjson.

leeonsoft avatar leeonsoft commented on July 17, 2024

I need mcjson to help me generate the correct json string so that other programs can parse it

from mcjson.

hydrobyte avatar hydrobyte commented on July 17, 2024

You can write a simple function in order to escape double quotes:

json.add('content').AsString:= MyEscapeDoubleQuotes('{"name":"111"}');

from mcjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.