Replace null values to empty values in a JSON OBJECT

前端 未结 8 1773
無奈伤痛
無奈伤痛 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:30

    If you can replace null-s with empty strings on serialized string, do something like this:

    data = JSON.parse(JSON.stringify(data).replace(/\:null/gi, "\:\"\"")); 
    

提交回复
热议问题