<legend id='N4oEQ'><style id='N4oEQ'><dir id='N4oEQ'><q id='N4oEQ'></q></dir></style></legend>

    1. <small id='N4oEQ'></small><noframes id='N4oEQ'>

    2. <tfoot id='N4oEQ'></tfoot>

        <bdo id='N4oEQ'></bdo><ul id='N4oEQ'></ul>
      1. <i id='N4oEQ'><tr id='N4oEQ'><dt id='N4oEQ'><q id='N4oEQ'><span id='N4oEQ'><b id='N4oEQ'><form id='N4oEQ'><ins id='N4oEQ'></ins><ul id='N4oEQ'></ul><sub id='N4oEQ'></sub></form><legend id='N4oEQ'></legend><bdo id='N4oEQ'><pre id='N4oEQ'><center id='N4oEQ'></center></pre></bdo></b><th id='N4oEQ'></th></span></q></dt></tr></i><div id='N4oEQ'><tfoot id='N4oEQ'></tfoot><dl id='N4oEQ'><fieldset id='N4oEQ'></fieldset></dl></div>

        'module'对象在使用python解析JSON时没有属性'loads'

        #39;module#39; object has no attribute #39;loads#39; while parsing JSON using python(module对象在使用python解析JSON时没有属性loads)
          <tbody id='KtfdP'></tbody>

        <tfoot id='KtfdP'></tfoot>

              1. <legend id='KtfdP'><style id='KtfdP'><dir id='KtfdP'><q id='KtfdP'></q></dir></style></legend>
                  <bdo id='KtfdP'></bdo><ul id='KtfdP'></ul>
                  <i id='KtfdP'><tr id='KtfdP'><dt id='KtfdP'><q id='KtfdP'><span id='KtfdP'><b id='KtfdP'><form id='KtfdP'><ins id='KtfdP'></ins><ul id='KtfdP'></ul><sub id='KtfdP'></sub></form><legend id='KtfdP'></legend><bdo id='KtfdP'><pre id='KtfdP'><center id='KtfdP'></center></pre></bdo></b><th id='KtfdP'></th></span></q></dt></tr></i><div id='KtfdP'><tfoot id='KtfdP'></tfoot><dl id='KtfdP'><fieldset id='KtfdP'></fieldset></dl></div>

                  <small id='KtfdP'></small><noframes id='KtfdP'>

                  本文介绍了'module'对象在使用python解析JSON时没有属性'loads'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I am trying to parse JSON from Python. I recently started working with Python so I followed some stackoverflow tutorial how to parse JSON using Python and I came up with below code -

                  #!/usr/bin/python
                  import json
                  
                  j = json.loads('{"script":"#!/bin/bash echo Hello World"}')
                  print j['script']
                  

                  But whenever I run the above code, I always get this error -

                  Traceback (most recent call last):
                    File "json.py", line 2, in <module>
                      import json
                    File "/cygdrive/c/ZookPython/json.py", line 4, in <module>
                      j = json.loads('{"script":"#!/bin/bash echo Hello World"}')
                  AttributeError: 'module' object has no attribute 'loads'
                  

                  Any thoughts what wrong I am doing here? I am running cygwin in windows and from there only I am running my python program. I am using Python 2.7.3

                  And is there any better and efficient way of parsing the JSON as well?

                  Update:-

                  Below code doesn't work if I remove the single quote since I am getting JSON string from some other method -

                  #!/usr/bin/python
                  
                  import json
                  
                  jsonStr = {"script":"#!/bin/bash echo Hello World"}
                  
                  j = json.loads(jsonStr)
                  shell_script = j['script']
                  print shell_script
                  

                  So before deserializing how to make sure, it has single quote as well?

                  This is the error I get -

                  Traceback (most recent call last):
                    File "jsontest.py", line 7, in <module>
                      j = json.loads(jsonStr)
                    File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
                      return _default_decoder.decode(s)
                    File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
                      obj, end = self.raw_decode(s, idx=_w(s, 0).end())
                  TypeError: expected string or buffer
                  

                  解决方案

                  File "json.py", line 2, in <module>
                    import json
                  

                  This line is a giveaway: you have named your script "json", but you are trying to import the builtin module called "json", since your script is in the current directory, it comes first in sys.path, and so that's the module that gets imported.

                  You need to rename your script to something else, preferrably not a standard python module.

                  这篇关于'module'对象在使用python解析JSON时没有属性'loads'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                  <legend id='5MWdp'><style id='5MWdp'><dir id='5MWdp'><q id='5MWdp'></q></dir></style></legend>
                    <bdo id='5MWdp'></bdo><ul id='5MWdp'></ul>
                  • <tfoot id='5MWdp'></tfoot>

                    <i id='5MWdp'><tr id='5MWdp'><dt id='5MWdp'><q id='5MWdp'><span id='5MWdp'><b id='5MWdp'><form id='5MWdp'><ins id='5MWdp'></ins><ul id='5MWdp'></ul><sub id='5MWdp'></sub></form><legend id='5MWdp'></legend><bdo id='5MWdp'><pre id='5MWdp'><center id='5MWdp'></center></pre></bdo></b><th id='5MWdp'></th></span></q></dt></tr></i><div id='5MWdp'><tfoot id='5MWdp'></tfoot><dl id='5MWdp'><fieldset id='5MWdp'></fieldset></dl></div>

                        <small id='5MWdp'></small><noframes id='5MWdp'>

                              <tbody id='5MWdp'></tbody>