Reputation: 132
The code I am working on is a function that converts a JSON object into iCalendar form. To do this, I am writing an iCalendar template, and then inserting the info from the JSON into that. My code requires JSON's decode which has caused me a lot of setbacks lately. Here is what I have tried and the error messages I am getting.
import json
def convert(jsonData)
....
data = json.decode(jsonData)
AttributeError: 'module' object has no attribute 'decode'
This error confuses me because the method is in the JSON API https://docs.python.org/2/library/json.html#module-json
import json
def convert(jsonData)
....
data = json.JSONDecoder().decode(jsonData)
TypeError: expected string or buffer
The second error references a line of code in decode(): line 366
end = self.raw_decode(s,idx=_w(s,o).end())
EDIT:
data = json.JSONDecoder.decode(jsonData)
TypeError: unbound method decode() must be called with JSONDecoder instance as first argument (got dict instance instead)
Upvotes: 0
Views: 279
Reputation: 1165
If jsonData
is a string, you just need json.loads(jsonData)
to convert it to a Python object.
Upvotes: 1