clean data in json遭遇

腫魔沒人留言?快點下去搶頭香啊!

目的:清除json中的空值或垃圾

  1. type()有可能遇到不是string,此時若沒判斷就會因為用replace()發生exception,當然如果用try statement也是可以的
  2. test one variable against multiple values可以用in
  3. 要注意是==str而非==’str’
for i in head.copy():
    if(type(head)==str):
        head = head.replace(' ', '') # 去除全形空白
    if(head in ('', None, '()', {}) or i==''):
        del head;
0 0 vote
Article Rating
訂閱(Subscribe)
來自於(Notify of)
0 Comments
Inline Feedbacks
View all comments