python 里面过滤
def del_none(d): """ Delete keys with the value ``None`` in a dictionary, recursively. This alters the input so you may wish to ``copy`` the dict first. """ # d.iteritems isn't used as you can't del or the iterator breaks. for key, value in d.items(): if value is None: del d[key] elif isinstance(value, dict): del_none(value) return d # For convenience ............... result_dic = { 'meta': { 'metaCode': 'Success', 'cost': cost, 'timestamp': end, 'postname': 'python' }, 'data': { 'image': image, 'title': title } } json.dumps(del_none(result_dic))
golang 里面过滤掉为 null 的字段
定义 omitempty
即可
type imageInfo struct { Width int `json:"width,omitempty"` Height int `json:"height,omitempty"` Author int `json:"author,omitempty"` Size int64 `json:"size,omitempty"` Format string `json:"format,omitempty"` Ua string `json:"ua,omitempty"` DecoderPlatform string `json:"DecoderPlatform,omitempty"` }
java 过滤掉不用 null 字段
略
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于