0

I am getting a JSON response from an API like this:

{"code": 200, "data": {"messageKey": {}, "returncode": "SUCCESS", "meetingID": "REG_561538474", "hasBeenForciblyEnded": "false", "moderatorPW": "58963", "attendeePW": "54321", "message": {}, "createTime": "1364280051568"}, "errors": null} 

Now I want to convert this into the Python object and save some value in a database.

Here is my code:

getmobject = Meeting() getj = json.loads(r.text) for x,v in getj.items(): if x == 'data': if x.meetingID:# == 'meetingID': getmobject.meetingID = x.meetingID if x.moderatorPW: getmobject.moderator_passwd = x.moderatorPW if x.attendeePW: getmobject.attendee_passwd = x.attendeePW getuser_main = User.objects.get(username = request.user.username) getmobject.name = get_meeting_name getmobject.created_by = getuser_main getmobject.sms_no = '12345' """Reminder we are making false as if participant accept then only meeting will able to initiate""" getmobject.reminder = False getmobject.save() 

But problem is I am getting the error:

'unicode' object has no attribute 'meetingID' 

Please help me out what might I am doing wrong here

1 Answer 1

1

In your code when x == "data", then v is the dictionary appeared in front of "data" in the json string, so you should use v["meetingID"] instead of x.meetingID and so on ...

Sign up to request clarification or add additional context in comments.

2 Comments

'dict' object has no attribute 'meetingID'
Yes I made mistake in my answer following your mistake ;-), You can not access dict items by .. Check the answer now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.