Matjaz Murko · Jul 10



How can I deserialize in C# JSON string created with %JSONExport - exported class includes property of type array of %String? Which type of property should I use in C# class to deserialize it properly (List<> doesn't work)?




Product version: IRIS 2020.1
1 0 5 98
Log in or sign up to continue

Please consider adding samples illustrating your issue:

  • ObjectScript class
  • C# class
  • C# code you're using do deserialize your JSON
  • JSON

ObjectScript class:

Class Packing.MasterData.Label Extends (%Persistent, %JSON.Adaptor) {

Property Department As %String;
Property Ident As %String;
Index LabelId On (Department, Ident) [ IdKey, Unique ];
Property Name As %String;
Index Name On Name;
Property Width As %Integer;
Property Height As %Integer;
Property DeclarationWidth As %Numeric;
Property DeclarationHeight As %Numeric;
Property ScriptTU As %Stream.FileBinary;
Property ScriptContainer As %Stream.FileBinary;
Property Status As %String(DISPLAYLIST = ",Aktivana,Neaktivna", VALUELIST = ",AC,NA") [ InitialExpression = "AC" ];
Property VarsXctsTU As array Of %String(MAXLEN = 500);
Property VarsXctsContainer As array Of %String(MAXLEN = 500);

Query List(Department As %String) As %SQLQuery(CONTAINID = 1) [ SqlProc ]
 SELECT Ident,Name FROM Label
 WHERE Department=:Department


C# class:

 private class SaveDataClass
            public string Name {get; set;}
            public int Width { get; set; }
            public int Height { get; set; }
            public double DeclarationHeight { get; set; }
            public double DeclarationWidth { get; set; }
            public byte[] ScriptTU { get; set; }
            public byte[] ScriptContainer { get; set; }
            public Object VarsXctsTU { get; set; }
            public Object VarsXctsContainer { get; set; }

C# deserialize code:

IRIS iris = IRIS.CreateIRIS(Program.Factory);
SaveDataClass aa=JsonSerializer.Deserialize<SaveDataClass>(iris.ClassMethodString("Packing.API.Administration", "LabelGetData", Program.Department, ddcLabelId.Text));

LabelGetData method:

ClassMethod LabelGetData(Department As %String, Ident As %String) As %String [ Language = objectscript ]
Set label=##class(Packing.MasterData.Label).LabelIdOpen(Department, Ident)
Quit:label="" "" Do label.%JSONExportToString(.json) Quit json


{"Ident":"CRO","Name":"HRVATSKI TEKST","VarsXctsTU":{"0":"..TechnicalProduct.Product.GTIN","1":"$Translate($ZDate(..UsefulBy,4,,2),\"/\",\".\")","2":"..Batch","3":"$FNUMBER(..CommercialWeight,\".\",3)","4":"..TechnicalProduct.Product.GTIN","5":"$TRANSLATE($JUSTIFY(..TechnicalProduct.Product.CUsInTU,2),\" \",0)","6":"$TRANSLATE($JUSTIFY($FNUMBER(..CommercialWeight*1000,,0),6),\" \",0)","7":"$EXTRACT($ZDate(..UsefulBy,8),3,*)","8":"..Batch","9":"$TRANSLATE($JUSTIFY(..%Id(),6),\" \",0)_$TRANSLATE($JUSTIFY(..TechnicalProduct.Ident,6),\" \",0)_$TRANSLATE($JUSTIFY(..TechnicalProduct.Product.CUsInTU,2),\" \",0)_$TRANSLATE($JUSTIFY($FNUMBER(..CommercialWeight*1000,,0),6),\" \",0)","10":"..TechnicalProduct.Ident","11":"\"001\"","12":"$SELECT(..TechnicalProduct.Product.Unit=\"KG\":$EXTRACT($TRANSLATE($JUSTIFY(..TechnicalProduct.EAN13TU,7),\" \",0),1,7)_$TRANSLATE($JUSTIFY($FNUMBER(..CommercialWeight*1000,,0),5),\" \",0),1:$EXTRACT($TRANSLATE($JUSTIFY(..TechnicalProduct.EAN13TU,12),\" \",0),1,12))","13":"$ZTime($ZTimeH($Piece(..CreatedAt,\" \",2),3),2)"}}

Properties for which I'm looking for solution are VarsXctsTU and VarsXctsContainer. Both are of type "array of %String". In C# class these properties are now declared as type Object, but they should be something like List<KeyValuePair<string,string>>, shouldn't they?

Have you tried to declare C# property like this:

public Dictionary<string, string> VarsXctsTU { get; set; }


I have tried everything except Dictionary. Tnx, it works!



Removing my reply as this was already answered.