Index: TECH/JSON/ParserIntersystemsVersion.cls.xml =================================================================== diff -u -r3756 -r3764 --- TECH/JSON/ParserIntersystemsVersion.cls.xml (.../ParserIntersystemsVersion.cls.xml) (revision 3756) +++ TECH/JSON/ParserIntersystemsVersion.cls.xml (.../ParserIntersystemsVersion.cls.xml) (revision 3764) @@ -396,8 +396,8 @@ Set JsonStringOutput = JsonStringOutput_" { " // add class name to model - Write !,"_class:'",tClass,"'" - Set JsonStringOutput = JsonStringOutput_"_class:'"_tClass_"'" + Write !,"klassenaam:'",tClass,"'" + Set JsonStringOutput = JsonStringOutput_"klassenaam:'"_tClass_"'" // cycle detection #; use class meta-data and @@ -586,6 +586,222 @@ Quit tSC ]]> + + +1 + +%Status +0 "," + If tPropCount>0 { + Set JsonStringOutput = JsonStringOutput_"," + } + Set tPropCount = tPropCount + 1 + + Write !,?(pLevel*3),tPropName,":" + Set JsonStringOutput = JsonStringOutput_" """_tPropName_""":" + Set tValue = $zobjproperty(pObject,tPropName) + } + + If (tMultiDim) { + } + ElseIf (tCollection="list") { + // list collection + Write "[" + Set JsonStringOutput = JsonStringOutput_"[" + If $IsObject(tValue) { + Set tList = tValue + Set tCount = tList.Count() + For n = 1:1:tCount { + Set tValue = tList.GetAt(n) + Write:n>1 "," + If n>1 { + Set JsonStringOutput = JsonStringOutput_"," + } + If (tClientType = "HANDLE") { + // object + If $IsObject(tValue) { + Set tSC = ..ObjectToJSONWithQuotedProps(tValue,.pVisited, pLevel + 1, .Json) + If $$$ISERR(tSC) { + Do ##class(Tools.Wlip).%New(43).String("handle error top") + Quit + } Else { + Set JsonStringOutput = JsonStringOutput_Json + } + Set Json = "" + } + Else { + Write "null" + Set JsonStringOutput = JsonStringOutput_"null" + } + } + Else { + Write $Case(tClientType,"BOOLEAN":$S(tValue:"true",1:"false"),:$S($IsValidNum(tValue):tValue,1:""""_$ZCVT(tValue,"O","JS")_"""")) + Set JsonStringOutput = JsonStringOutput_$Case(tClientType,"BOOLEAN":$S(tValue:"true",1:"false"),:$S($IsValidNum(tValue):tValue,1:""""_$ZCVT(tValue,"O","JS")_"""")) + } + } + } + Write "]" + Set JsonStringOutput = JsonStringOutput_"]" + } + ElseIf (tCollection="array") { + // array collection (object on client) + Write "{" + Set JsonStringOutput = JsonStringOutput_"{" + If $IsObject(tValue) { + Set tArray = tValue + Set n = 0 + Set tKey = tArray.Next("") + While (tKey '= "") { + Set n = n + 1 + Write:n>1 "," + If n>1 { + Set JsonStringOutput = JsonStringOutput_"," + } + Set tValue = tArray.GetAt(tKey) + Write $S($zname(tKey):tKey,$IsValidNum(tKey):tKey,1:""""_$ZCVT(tKey,"O","JS")_""""),":" + Set JsonStringOutput = JsonStringOutput_""""_$S($zname(tKey):tKey,$IsValidNum(tKey):tKey,1:""""_$ZCVT(tKey,"O","JS")_"""")_""":" + + If (tClientType = "HANDLE") { + // object + If $IsObject(tValue) { + Set tSC = ..ObjectToJSONWithQuotedProps(tValue,.pVisited, pLevel + 1, .Json) + If $$$ISERR(tSC) { + Do ##class(Tools.Wlip).%New(43).String("handle error") + Quit + } Else { + Set JsonStringOutput = JsonStringOutput_Json + } + Set Json = "" + } + Else { + Write "null" + Set JsonStringOutput = JsonStringOutput_"null" + } + } + Else { + Write $Case(tClientType,"BOOLEAN":$S(tValue:"true",1:"false"),:$S($IsValidNum(tValue):tValue,1:""""_$ZCVT(tValue,"O","JS")_"""")) + Set JsonStringOutput = JsonStringOutput_$Case(tClientType,"BOOLEAN":$S(tValue:"true",1:"false"),:$S($IsValidNum(tValue):tValue,1:""""_$ZCVT(tValue,"O","JS")_"""")) + } + + Set tKey = tArray.Next(tKey) + } + } + Write "}" + Set JsonStringOutput = JsonStringOutput_"}" + } + ElseIf (tClientType = "HANDLE") { + // object + If $IsObject(tValue) { + Set tSC = ..ObjectToJSONWithQuotedProps(tValue,.pVisited, pLevel + 1,.Json) + If $$$ISERR(tSC) { + Quit + } Else { + Set JsonStringOutput = JsonStringOutput_Json + } + Set Json = "" + } + Else { + Write "null" + Set JsonStringOutput = JsonStringOutput_"null" + } + } + ElseIf (tClientType = "CHARACTERSTREAM") { + If $IsObject(tValue) { + // turn on io escaping + Write """" + Set JsonStringOutput = JsonStringOutput_"""" + Set io = $$$GETIO + $$$SETIO("JSML") + Do tValue.Rewind() + Do tValue.OutputToDevice() + $$$SETIO(io) + Write """" + Set JsonStringOutput = JsonStringOutput_"""" + } + Else { + Write "null" + Set JsonStringOutput = JsonStringOutput_"null" + } + } + ElseIf (tClientType = "BINARYSTREAM") { + Write "null" + Set JsonStringOutput = JsonStringOutput_"null" + } + Else { + Write $Case(tClientType,"BOOLEAN":$S(tValue:"true",1:"false"),:$S($IsValidNum(tValue):tValue,1:""""_$ZCVT(tValue,"O","JS")_"""")) + Set JsonStringOutput = JsonStringOutput_$Case(tClientType,"BOOLEAN":$S(tValue:"true",1:"false"),:$S($IsValidNum(tValue):tValue,1:""""_$ZCVT(tValue,"O","JS")_"""")) + } + } + Set tPropName = $$$comMemberNext(tClass,$$$cCLASSproperty,tPropName) + } + If $$$ISERR(tSC) Quit + + Write !,?(pLevel*3),"}" + Set JsonStringOutput = JsonStringOutput_"}" + } + Catch(ex) { + Set tSC = ex.AsStatus() + Write "null" + Set JsonStringOutput = "" + } + Quit tSC +]]> +