开发者社区> 问答> 正文

json数据值读取时 提示typeerror错误?报错

从json 文件里读取想要的内容,我会判断取出来的记录中对应的属性值是否为空,并加相关的处理代码,但是运行时还是会报typeerror:nonetype  Object has  no attribute  getitem  。求大神帮忙看看。

代码如下:

            geo = geoSpider.crawl(poi[u'point'][u'y'],poi[u'point'][u'x'],0)

            if len(geo[u'addressComponent'][u'province'])>0:
                result[u'province'] = geo[u'addressComponent'][u'province']
            else:
                result[u'province']=''

运行报错如下

Exception in thread Thread-5:
Traceback (most recent call last):
  File "C:\Anaconda\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "get_pois.py", line 55, in run
    poi_msg = FetchCompanyInformation(msg['point'].lat,msg['point'].lng)
  File "get_pois.py", line 138, in FetchCompanyInformation
    if len(geo[u'addressComponent'][u'province'] )>0:
TypeError: 'NoneType' object has no attribute '__getitem__'


展开
收起
爱吃鱼的程序员 2020-06-09 10:54:03 656 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    最可能是geo[u'addressComponent']是None了

    2020-06-09 10:54:18
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载