serialize from object to %string
hello!
i have object bellow
set object.city = "New York"
set object.Target = "TEST"
set object.Details = "TEST"
set object.RefCode = "123"
set object.Reason = "123TTTT"
I want to get string from json object.
Could you help please ?
Product version: Caché 2017.1
$ZV: Cache for UNIX (Red Hat Enterprise Linux for x86-64) 2017.2.2 (Build 867_4_20165U) Mon Aug 17 2020 11:28:28 EDT
You can manipulate object.city, for example like a string :
Do you want to serialize it?
yes.
Hope this could help:
Stolen from @Kyle Baxter answer here.
WHO DARES SUMMON ME!
) but note that in newer versions (IRIS, for instance), you can make use of the %JSON.Adaptor to do something like:
Oh, hi Evgeny! Great to see you, hope you're well!
For everyone else, Evgeny is right, of course (because he's quoting me
{
Property aString As %String;
Property anInteger As %Integer;
}
The do something like:
s obj=##class(Test.DoesItJSON).%New()
s obj.aString="Hello"
s obj.anInteger=123
d obj.%JSONExportToString(.jsonstring)
zw jsonstring
jsonstring="{""aString"":""Hello"",""anInteger"":123}"
This is better for creating new classes (again in later versions than you're on, you need to use the jsonProvider or the altJsonProvider) that you think you're going to want to serialize into JSON.
Great to see you, Kyle!
Yes, this was a part of the plan )) Welcome back!
Thank you!
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue