TDstring = TDictionary<double, string>;
class procedure c_method.CustomReadClass(var Context: TJsonParserContext; Instance: TObject);
var
doc: TDocVariantData;
begin
if Context.ParseObject then
begin
if not assigned(Instance) then
Instance := TDstring.Create;
TDstring(Instance).Clear;
var s : u8string := add_bracket(Context.json); //'{ ' + Context.json + ' }'
doc.InitJson(s);
var nameList := doc.Names;
for var i :integer := 0 to High(nameList) do
begin
TDstring(Instance).TryAdd(To_string(nameList[i]).ToDouble, doc.s[nameList[i]]);
end;
Context.ParseEndOfObject;
Context.Valid := true;
end;
end;
initialization
TRttiJson.RegisterCustomSerializerClass(TDstring, c_method.CustomReadClass, nil);
finalization
TRttiJson.UnRegisterCustomSerializerClass(TDstring);
Thanks again!
]]>Just like:
TPairString = TPair<double, string>;
TPairstrings = TArray<TPairString>;
PPairstrings = ^TPairstrings;
TDictStringMethod = class
public
class procedure CustomReader(var Context: TJsonParserContext; data: pointer);
class procedure CustomWriter(W: TJsonWriter; data: pointer; Options: TTextWriterWriteObjectOptions);
end;
initialization
TRttiJson.RegisterCustomSerializer(typeinfo(PPairstrings), TdictStringMethod.CustomReader, TdictStringMethod.CustomWriter);
Can this be work?
]]>But I can't use a json string , such as :"{"name":"mark","data":[1,2,3,4,5],"some":{"11.1":"Hello","22.2":",","44.4":"World"}}".
const
_JSON = '{"name":"mark","data":[1,2,3,4,5],"some":{"11.1":"Hello","22.2":",","44.4":"World"}}';
var
doc: TDocVariantData;
begin
if doc.InitJson(_JSON) then
begin
ShowMessage(doc.S['name']);
ShowMessage(doc.O['some'].S['11.1']);
ShowMessage(VarToStr(doc.A['data'].Value[1]));
end;
With best regards
Thomas
It is so sad~
Maybe I must translater a std::multimap to a std::vector and save it, then I'm able to load and use it in delphi.
]]>You can access the TSynDictionary instance from IKeyValue<integer, string>.Data.
And don't use TIKeyValue<integer, string> but Collections.NewKeyValue<integer, string>.
For some reference about TSynDictionary, see TTestCoreBase._TSynDictionary regression tests.
]]>so in delphi i try to serialization a example data,such as: Tarray<Tpair<integer,string>>,but the result is {[{"Key":1,"Value":"Hello"},{"Key":2,"Value":"World"}]}.
how can i deserialization "{"1":"Hello","2":"world"}" and use it in delphi??
thanks!
]]>