如何在python中检查输入json数据中的空白字段?
假设在我的python-below函数中,我得到了如下所示的json提要如何在python中检查输入json数据中的空白字段?,python,json,parsing,python-2.7,python-3.x,Python,Json,Parsing,Python 2.7,Python 3.x,假设在我的python-below函数中,我得到了如下所示的json提要 def mapper_1(self, key, line): j_feed = json.loads(line) unicoded = j_feed[u'category_description'].encode("utf-8") cn = j_feed[u'categoryname'] location = j_feed[u'location'] 如何从input.json检查categoryname
def mapper_1(self, key, line):
j_feed = json.loads(line)
unicoded = j_feed[u'category_description'].encode("utf-8")
cn = j_feed[u'categoryname']
location = j_feed[u'location']
如何从input.json检查categoryname/categorydescription/location中的数据是否有空白字段。如果您不确定字段,可以使用
.get
并为其提供默认sentinel值
fields = ['categoryname', 'categorydescription', 'location']
for field in fields:
print j_feed.get(field, "not set!")
如果str.strip()
或如果str为None
?