how to convert JSON to object in cache 2010 version
Hello,
I'm trying to convert JSON response to object in cache 2010.
My Code is bellow:
my JSON response
the result :
Comments
Looks like it works correctly.
write pObjectoutputs the object oref.
If you want to display the whole object, use zwrite:
zwrite pObjectIf you need a specific property, access them like this:
write pObject."access_token"
write pObject.inHello Eduard! Thank you for feedback.
In my case it doesn't work, the output:
Set ^tk("access_token1")=pObject."access_token"
Set ^tk("access_token2")=pObject.in
the response:
^tk("access_token2")=""
^tk("object")="9@%ZEN.proxyObject"
What will the following code output?
USER>k arr d pObject.%CopyToArray(.arr) zw arr
PS: "in" ≠ "expires_in"
d pObject.%CopyToArray(.arr)
Error: <UNDEFINED>*arr
What will the following code output?
s resptext="{""access_token"":""4SDFDSFDSF-aSDASDASD"",""expires_in"":""3300"",""refresh_token"":"""",""scope"":""sms_send"",""token_type"":""Bearer""}"
s sc = ##class(%ZEN.Auxiliary.jsonProvider).%ParseJSON(resptext,,.pObject,1)
i $$$ISOK(sc) {
w pObject,!!,
pObject."access_token",!,
pObject."expires_in",!
k arr s arr="" d pObject.%CopyToArray(.arr) zw arr
}else{
d $system.OBJ.DisplayError(sc)
}My result (2018.1):
USER>d ^test
1@%ZEN.proxyObject
4SDFDSFDSF-aSDASDASD
3300
arr("access_token")="4SDFDSFDSF-aSDASDASD"
arr("expires_in")=3300
arr("refresh_token")=""
arr("scope")="sms_send"
arr("token_type")="Bearer"What does this output in a terminal:
set respText="{""access_token"":""4SDFDSFDSF-aSDASDASD"",""expires_in"":""3300"",""refresh_token"":"""",""scope"":""sms_send"",""token_type"":""Bearer""}"
set sc = ##class(%ZEN.Auxiliary.jsonProvider).%ParseJSON(respText,,.pObject,1)
zw pObjectI tried it on a later verison and got:
pObject=<OBJECT REFERENCE>[1@%ZEN.proxyObject]
+----------------- general information ---------------
| oref value: 1
| class name: %ZEN.proxyObject
| reference count: 2
+----------------- attribute values ------------------
| %changed = 1
|%data("access_token") = "4SDFDSFDSF-aSDASDASD"
|%data("expires_in") = 3300
|%data("refresh_token") = ""
| %data("scope") = "sms_send"
|%data("token_type") = "Bearer"
| %index = ""
+-----------------------------------------------------