2019-08-09

2019-08-09  本文已影响0人  阿阿潇

1.已知节点路径

def selectJsonBykeyChain(keyChain, json):
    # keyChain 'a.b.c'
    keyList = str.split(keyChain, '.')
    val = json;
    for k in keyList:
        # print(k)
        val = val[k]
    return val

2.已知节点key值

def selectJsonByKey(key, jsonb):
    for k in jsonb:
       if k==key:
           return jsonb[k]
       chlidType = type(jsonb[k])
       if dict == chlidType:
           print('进入到了子节点'+k)
           return selectJsonByKey(key,jsonb[k])
上一篇下一篇

猜你喜欢

热点阅读