Replace null values to empty values in a JSON OBJECT

前端 未结 8 1757
無奈伤痛
無奈伤痛 2020-12-31 06:54

Hi I\'ve got a JSON object provided by an ajax request.

Some of the values inside the json appears as null, but I want an empty String inst

8条回答
  •  情歌与酒
    2020-12-31 07:27

    Hope this help

    var List = [];
    
    
    $.post("/profil_process/wall/preview-post.php",param, function (data){
    
    jQuery.each(data, function (key, value) {
                    List.push({
                        ReportId : value.ReportId,
                        ReportType: CheckNullReturnBlank(value.ReportType),
                        ReportName: CheckNullReturnBlank(value.ReportName),
                        Description : CheckNullReturnBlank(value.Description)
                    })
                });   },'json');
    
    
    
    function CheckNullReturnBlank(item) {
        return item = (item == null) ? '' : item;
    }
    

提交回复
热议问题