473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

4 New Member
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 3271
Jagdeep
4 New Member
I tried. This statement JSONDecoder().d ecode(printJson ). But It's not working.
Sep 5 '15 #2
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
Expand|Select|Wrap|Line Numbers
  1. JD=JSONDecoder()  ## creates class instance
  2. print JD.decode(printJson)
Sep 5 '15 #3
Jagdeep
4 New Member
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 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.
Sep 6 '15 #5
Jagdeep
4 New Member
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
1917
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 equal. How else can I determine this? BTW, I'm using Python 2.3 Thanks, Farshid
4
9357
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 test instance as first argument (got test instance instead)" Below is the sample code (test) for this purpose (two files). Any help is greatly appreciated.
10
46425
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 regarding them, but haven't come across these descriptions in any of my reading material so far. Thanks!
2
1959
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(). Within that class I call various methods, including drawGUI() and authorizeDump(). My problem comes when I try to call authorizeDump from the Tkinter menu. Here is the code that calls authorizeDump(): self.packetmenu.add_command(label="Start...
2
13923
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 following error: Traceback (innermost last): File "/full/path/to/file/GenerateData.py", line 104, in ? File "/full/path/to/file/GenerateData.py", line 34, in __init__ TypeError: unbound method must be called with class instance 1st argument
1
3503
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 foo(self): pass Foo.foo() # error: unbound method foo().
2
2631
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 turtle module to draw the body of a car with body class. The class needs to have a init method and a draw method. The init method is supposed to determine fill color and draw is supposed to draw the object. heres some of my code: ...
3
2659
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 information (val_1) up to def. valt_ar to continue calculate.. ------------------------------------ from time import* import time class Kalender:
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6163
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.