<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'

        时间:2024-04-21
          <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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将 Pandas 数据框转换为嵌套 JSON 下一篇:字典是在 Python 3.6+ 中排序的吗?

                  相关文章

                  <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'>