는 말 사전을 평평하게세미 나는이 사전을 가지고
중첩은 2 또는 3 단계로 제한되어서는 안
pool_JP_longname: Jackpot
pool_JP_poolTotal: 318400
etc
etc
, 그래서 그것은 일반적이어야합니다.
또는 다른 예 :
{
"soccer": {
"X07": {
"date": "2013-11-22",
"poolType": "S10",
"code": "INT",
"closeTime": "20:00:00",
"poolStatus": "OP",
"pool": {
"1": {
"startRace": 1,
"matchs": {
"1": {
"teamA": "Ajax Cape Town",
"teamB": "Moroka Swallows",
"matchStatus": "OP"
},
"2": {
"teamA": "Bidvest Wits",
"teamB": "MP Black Aces",
"matchStatus": "OP"
}
}
}
}
}
}
}
이과 같습니다
soccer_X07_data: "2013-11-22"
soccer_X07_poolType: "S10"
etc
soccer_X07_pool_1_matchs_1_teamA
soccer_X07_pool_1_matchs_1_teamB
etc
나는 이런 식으로 일을 시작했다, 그러나 이것은 올바르지 않습니다 :
def iterTool(json_data, key_string):
for root_key, item in sorted(json_data.items(), key=itemgetter(0)):
if type(json_data[root_key]) == dict:
key_string += "_%s" % root_key
if json_data[root_key].keys():
for parent_key in json_data[root_key]:
if type(json_data[root_key][parent_key]) in [unicode]:
print "%s_%s" % (key_string, parent_key)
# print key_string.split("_")
# pass
iterTool(json_data[root_key], key_string)
이는 것 외출 :
_soccer_X07_code
_soccer_X07_poolStatus
_soccer_X07_closeTime
_soccer_X07_poolType
_soccer_X07_date
_soccer_X07_pool_1_matchs_1_matchStatus
_soccer_X07_pool_1_matchs_1_teamA
_soccer_X07_pool_1_matchs_1_teamB
_soccer_X07_pool_1_matchs_1_10_matchStatus
_soccer_X07_pool_1_matchs_1_10_teamA
_soccer_X07_pool_1_matchs_1_10_teamB
_soccer_X07_pool_1_matchs_1_10_2_matchStatus
_soccer_X07_pool_1_matchs_1_10_2_teamA
_soccer_X07_pool_1_matchs_1_10_2_teamB
_soccer_X07_pool_1_matchs_1_10_2_3_matchStatus
_soccer_X07_pool_1_matchs_1_10_2_3_teamA
_soccer_X07_pool_1_matchs_1_10_2_3_teamB
_soccer_X07_pool_1_matchs_1_10_2_3_4_matchStatus
_soccer_X07_pool_1_matchs_1_10_2_3_4_teamA
_soccer_X07_pool_1_matchs_1_10_2_3_4_teamB
_soccer_X07_pool_1_matchs_1_10_2_3_4_5_matchStatus
_soccer_X07_pool_1_matchs_1_10_2_3_4_5_teamA
...
이제 또 다른 커브 ..
하자가 딕셔너리는 다음과 같습니다 말 :
GENERIC_KEY : CAP, COUNTRYNAME는 못해 오히려 평평하게하는 것은 의미가
다음{
"CAP": {
"countryName": "ZAF",
"displayName": "AN"
},
"SPA": {
"countryName": "AUs",
"displayName": "AG"
}
}
: ZAF, displayName : AN
어떻게 감지합니까?
"커브 볼"은 별도의 질문입니다. – jonrsharpe
물론이 질문은 별도의 질문으로하겠습니다. 도와 주셔서 감사합니다 – Harry