#1 mORMot 1 » Difficulty using VariantLoadJSON from VariantSaveJSON string. » 2021-04-23 05:54:18

CalebB
Replies: 1

Hello,

I've been working on a cross platform solution sending data from a windows server to an Android phone and was using variants with VariantSaveJSON on the windows server side and repacking them with the TJSONVariantData (in SynCrossPlatformJSON) on the Android side. This has been working great and I'm now implementing the same thing, but this time on arm-linux (Latest stable Lazarus and FPC), without the cross platform libraries. VariantLoadJSON is not cooperating nicely and I'm unsure as to why, and am pretty sure this is an issue in my understanding.

Windows server side:

var
  lVariant : Variant;
begin
  lVariant := _Obj(['License','','Extensions',_Arr([]),'Time','','FrameType','','PlayTone','','LockOut','','Duress','','HoldLength','']);
  //Package up the lVariant object with data
  result := VariantSaveJSON(lVariant);
  //Send the resulting string to the client
end

Client side:

var
  lVariant : Variant;
  lVarJSON : RawUTF8;
  lLicense : RawUTF8;
begin
  lVarJSON := {"License":"LAS Herston", "Extensions":["CBN", "JBD"], "Time":"23/04/2021 04:28:24", "FrameType":0, "PlayTone":1, "LockOut":1, "Duress":0, "HoldLength":2};
  lVariant := VariantLoadJSON(lVarJSON);
  lLicense := lVariant.License;

Trying to assign lLicense provides an EVariantInvalidOpError exception with the message "Invalid variant operation". I know I can create and pack a variant using the same fields and immediately retrieve the data with that syntax no issues but trying to create the vairant from JSON is giving me a hard time.

Is there something obvious I'm missing, or am I misunderstanding how to use JSONLoadVariant?

Thanks kindly,
-Caleb

Board footer

Powered by FluxBB