TypeError: unbound method decode() must be called with JSONDecoder instance as first argument (got PrintJson instance instead)
I am getting this error when I try to parse python object into json.
Using following code:- - import json
-
from json import JSONDecoder
-
-
class TestJson():
-
name = None
-
pass
-
-
printJson = PrintJson()
-
print printJson
-
print JSONDecoder.decode(printJson) // at this line, getting this error
5 3262
I tried. This statement JSONDecoder().decode(printJson). But It's not working.
dwblas 626
Recognized Expert Contributor
TypeError: unbound method decode() must be called with JSONDecoder instance
Don't know anything about this package but the error message says you use an instance of JSONDecoder, something like - JD=JSONDecoder() ## creates class instance
-
print JD.decode(printJson)
Thanks for reply,
I tried but it's not working. Facing below mentioned error, after using with instance "JD".
ERROR:- -
File "C:\Users\jagdeep\test\json_test.py", line 70, in <module>
-
<json_test.PrintJson object at 0x000000000262AF28> print jsd.decode(printJson)
-
Now try to use json decode
-
File "C:\Python27\lib\json\decoder.py", line 366, in decode
-
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
-
TypeError: expected string or buffer
dwblas 626
Recognized Expert Contributor
The error is obvious. It requires a string so do a "print type(printJson)" before the error line and if it is a type that can be converted to a string, you can pass str(printJson) to the function.
-
import json
-
from json import JSONDecoder
-
from json import JSONEncoder
-
-
class PrintJSON(object):
-
name = None
-
pass
-
printJson = PrintJSON()
-
printJson.name = "This is test"
-
-
-
jd = JSONDecoder()
-
print(jd.decode(str(printJson)))
-
-
But getting error:-
-
Traceback (most recent call last):
-
File "C:/Users/jagdeep/test/json_test2.py", line 15, in <module>
-
print(jd.decode(str(printJson)))
-
File "C:\Python27\lib\json\decoder.py", line 366, in decode
-
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
-
File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
-
raise ValueError("No JSON object could be decoded")
-
ValueError: No JSON object could be decoded
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Farshid Lashkari |
last post by:
Hi,
I have an object and I want to check if it is a bound or unbound method,
or neither. I tried using the types module, but it seems as though
types.UnboundMethodType and types.MethodType are...
|
by: arotem |
last post by:
Hi,
I am trying to call an unbound method (PrintInput) with the object
instance as the first argument but getting the following error:
"TypeError: unbound method PrintInput() must be called with...
|
by: true911m |
last post by:
Can someone give me a quick rundown on the difference between bound and unbound methods? I ran into an error regarding an unbound method, and found lots of discussions about changing Python behavior...
|
by: Kevin Walzer |
last post by:
I am trying to structure a Tkinter application with classes instead of
just with simple functions, but I'm not sure how to call methods from my
main class.
My main class is packetstreamApp()....
|
by: void.no.spam.com |
last post by:
I'm a novice at Python, and found some code samples on how to use
threads. My script is being run by a product that contains a Jython
interpreter. Can someone please explain why I get the...
| |
by: cinsky |
last post by:
Hi, I got confused when I learned the function datetime.today().
So far I learned, unless an instance is created, it is not possible to
call the class method. For example:
class Foo:
def...
|
by: kevow123 |
last post by:
TypeError: unbound method draw() must be called with Body instance as first argument (got Turtle instance instead)
I get that error when I attempt to run my program in python. I have to use the...
|
by: jpersson |
last post by:
Hi
I am making a calendar (in Swedish): have problems with the Type Error. The problem i s that the user type in under val_1 what year he or she want to se a calendar of. The I want to send that...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |