python的新手(可以使用php以及)..搜索各種網站/ SO ..並仍然有一個心理障礙。將json列表簡化爲獨特的字典項目
得到了JSON,並試圖找出如何拍攝包含類型的字典列表,並創建一個具有一套獨特的類型的字典結果列表..
作爲
的一個實例,下面是測試列表:
[{"pStart1a": {"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI",
"instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH",
"pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"},
"pSearch1a":
{"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}},
{"pStart1":""},
{"pStart1a":{"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI",
"instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH",
"pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"},
"pSearch1a":
{"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}},
{"pStart1":""}]
試圖獲得以下,唯一的字典列表,所以沒有重複的字典。
[
{"pStart1a":
{"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI",
"instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH",
pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"},
"pSearch1a":
{"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}},
{"pStart1":""}]
我正在考慮通過初始列表進行迭代,每一個複製詞典到一個新的列表,並做了基本的比較,將在未來字典,如果它不在新的清單..有另一個/更好的辦法?
感謝
是否有原因,你不使用Python的內置json庫? – Peter 2012-01-10 18:17:15
它是否存在實際問題?你會如何處理結果列表?也許你可以使用不同的格式或簡化數據? – reclosedev 2012-01-10 19:23:51