473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

TypeError: unbound method decode() must be called with JSONDecoder instance as first

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

Expand|Select|Wrap|Line Numbers
  1. import json
  2. from json import JSONDecoder
  3.  
  4. class TestJson():
  5.     name = None
  6.     pass
  7.  
  8. printJson = PrintJson()
  9. print printJson
  10. print JSONDecoder.decode(printJson) // at this line, getting this error
Sep 5 '15 #1
5 3260
I tried. This statement JSONDecoder().decode(printJson). But It's not working.
Sep 5 '15 #2
dwblas
626 Expert 512MB
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
Expand|Select|Wrap|Line Numbers
  1. JD=JSONDecoder()  ## creates class instance
  2. print JD.decode(printJson)
Sep 5 '15 #3
Thanks for reply,

I tried but it's not working. Facing below mentioned error, after using with instance "JD".
ERROR:-
Expand|Select|Wrap|Line Numbers
  1. File "C:\Users\jagdeep\test\json_test.py", line 70, in <module>
  2. <json_test.PrintJson object at 0x000000000262AF28>    print jsd.decode(printJson)
  3. Now try to use json decode
  4.   File "C:\Python27\lib\json\decoder.py", line 366, in decode
  5.     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  6. TypeError: expected string or buffer
Sep 6 '15 #4
dwblas
626 Expert 512MB
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.
Sep 6 '15 #5
Expand|Select|Wrap|Line Numbers
  1. import json
  2. from json import JSONDecoder
  3. from json import JSONEncoder
  4.  
  5. class PrintJSON(object):
  6.     name = None
  7.     pass
  8. printJson = PrintJSON()
  9. printJson.name = "This is test"
  10.  
  11.  
  12. jd = JSONDecoder()
  13. print(jd.decode(str(printJson)))
  14.  
  15. But getting error:-
  16. Traceback (most recent call last):
  17.   File "C:/Users/jagdeep/test/json_test2.py", line 15, in <module>
  18.     print(jd.decode(str(printJson)))
  19.   File "C:\Python27\lib\json\decoder.py", line 366, in decode
  20.     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  21.   File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
  22.     raise ValueError("No JSON object could be decoded")
  23. ValueError: No JSON object could be decoded
  24.  
Sep 6 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
4
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...
10
true911m
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...
2
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()....
2
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...
1
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...
2
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.