Est-il possible d'exclure certains champs de l'inclusion dans la chaîne json?
Voici un pseudo code
var x = {
x:0,
y:0,
divID:"xyz",
privateProperty1: 'foo',
privateProperty2: 'bar'
}
Je veux exclure privateProperty1 et privateproperty2 d'apparaître dans la chaîne json
Alors j'ai pensé, je peux utiliser la fonction de remplacement stringify
function replacer(key,value)
{
if (key=="privateProperty1") then retun "none";
else if (key=="privateProperty2") then retun "none";
else return value;
}
et dans le stringify
var jsonString = json.stringify(x,replacer);
Mais dans le jsonString, je le vois toujours comme
{...privateProperty1:value..., privateProperty2:value }
Je voudrais la chaîne sans les propriétés privées en eux.