これを Json で何らかの方法で検出できますか?
{"a": null} Explicitly set a field to null VS
{} Not pass that field in at all ?
Json は両方の条件を null と見なしますが、この違いを検出する方法はありますか?
これを Json で何らかの方法で検出できますか?
{"a": null} Explicitly set a field to null VS
{} Not pass that field in at all ?
Json は両方の条件を null と見なしますが、この違いを検出する方法はありますか?
前者の場合 ( object = {"a": null}
)、オブジェクトには という名前のフィールドa
があり、その値はnull
です。後者の ( object = {}
) では、フィールドa
はundefined
オブジェクト用です。つまり、オブジェクトにはそのようなフィールドはありません。
if(object.a)
condition は両方のケースで false を返します。ただし、if (object.a === undefined)
後者の場合のみ true を返します。したがって、このチェックを使用して 2 つのケースを区別できます。