Jamzaddy
Jamzaddy

Reputation: 73

How to get value using key in python multi dictionary

{
 "card_quota": 0,
 "custom_data": "{\"child_name\":\"홍설\",\"uid\":\"29\",\"lid\":\"56\",\"count\":\"1\",\"schedule\":\"2016-06-18(토)\"}",
 "escrow": false
}

This is dictionary type of python. I konw to get value using a code like temp['card_quata']. But i want to know using key in ['custom_data'] getting value like child_name or uid .. How can i do that?

Upvotes: 1

Views: 290

Answers (2)

niemmi
niemmi

Reputation: 17273

You can parse custom_data with json.loads and then access the returned dict:

>>> import json
>>> json.loads(temp['custom_data'])['child_name']
'홍설'

Note that the example data you provided is not valid Python since Python uses False instead of false.

Upvotes: 4

Vikas Ojha
Vikas Ojha

Reputation: 6950

You can simply get the values of any dictionary using the keys. So lets take it step by step: first, lets get the dictionary -

temp['custom_data']

will give you the child dictionary, then, in order to access the items of this child dict, you can use the child keys:

temp['custom_data']['child_name']
temp['custom_data']['uid']

etc.

Upvotes: -1

Related Questions