只要您与服务器的协议达成一致,上述任何内容都可以工作,但如果您从服务器传递空值,我相信这会使您的 API 以后更加灵活。
还应该提到 javascript 的 hasOwnProperty 函数可以让您进一步了解。
/* if true object DOES contain the property with *some* value */
if( objectFromJSON.hasOwnProperty( "propertyName" ) )
/* if true object DOES contain the property and it has been set to null */
if( jsonObject.propertyName === null )
/* if true object either DOES NOT contain the property
OR
object DOES contain the property and it has been set to undefined */
if( jsonObject.propertyName === undefined )