Json格式返回前端去除部分字段

2021-09-12 11:25:32 字數 508 閱讀 5403

後台對外開放介面時,經常會有一些後台需要的字段。但是前端是不需要的。

為了**的整潔 也為了返回類沒有富裕字段所以經常需要過濾掉不需要的字段。

我們常常使用json來作為前後端傳輸的載體,所以介紹一種去除富裕欄位的方法。

/**

* 過濾不需要的字段

*/******propertyprefilter propertyprefilter = new ******propertyprefilter();

listexcludefields = lists.newarraylist();

//要過濾的欄位名稱 ****

excludefields.add("****");

propertyprefilter.getexcludes().addall(excludefields);

string json = json.tojsonstring(new object(),propertyprefilter);

前端去除預設屬性

charset utf 8 body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,textarea,p,blockquote,th,td,input,select,textarea,button 初始化標...

Django vue返回json格式

django返回json格式資料 json list為array返回json格式的陣列對於django將model轉為dict的方法 from django.forms.models import model to dict for good in goods json dict model to ...

Springboot返回json格式

該技術是解決springboot如何返回json格式的問題。學習該技術的起因是我們組的專案需要介面返回json格式,有時還需要多重巢狀返回要求的格式。技術難點 主要在返回巢狀json格式,如何正確的裝配並返回也是乙個難點。核心是使用restcontroller關鍵字 restcontroller p...