第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

是否有任何 JSON 標(biāo)記篩選示例?

是否有任何 JSON 標(biāo)記篩選示例?

哈士奇WWW 2022-09-13 19:55:36
我有一個json文件,我需要列出所有數(shù)據(jù)的所有“自文本”元素。任何例子?數(shù)據(jù)示例{   "data": [    {              "selftext": "hello there",        "textex": true,   },
查看完整描述

1 回答

?
至尊寶的傳說

TA貢獻1789條經(jīng)驗 獲得超10個贊

如果您希望能夠在任意級別從任意 json 中找到密鑰,則應(yīng)使用遞歸:


def findkey(data, key, resul = None):

    if resul is None: resul=[]                # initialize an empty list for the results

    if isinstance(data, list):                # walk down into lists

        for d in data:

            findkey(d, key, resul)

    elif isinstance(data, dict):              # dict processing

        for k,v in data.items():

            if (k == key) and isinstance(v, str):    # the expected key and a string value?

                resul.append(v)

            elif isinstance(v, list) or isinstance(v, dict):

                findkey(v, key, resul)        # recurse if value is a list or a dict

    return resul

例:


>>> data = {   "data": [

    {

        "selftext": "hello there",

        "textex": True,


   },

  ]}

>>> findkey(data, 'selftext')

['hello there']


查看完整回答
反對 回復(fù) 2022-09-13
  • 1 回答
  • 0 關(guān)注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號