Is it possible to exclude certain fields from being included in the json string?
Here is some pseudo code
var x = {
x:0,
y:0,
divID:"xyz",
privateProperty1: 'foo',
privateProperty2: 'bar'
}
I want to exclude privateProperty1 and privateproperty2 from appearing in the json string
So I thought, I can use the stringify replacer function
function replacer(key,value)
{
if (key=="privateProperty1") then retun "none";
else if (key=="privateProperty2") then retun "none";
else return value;
}
and in the stringify
var jsonString = json.stringify(x,replacer);
But in the jsonString I still see it as
{...privateProperty1:value..., privateProperty2:value }
I would like to the string without the privateproperties in them.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…