我想從文件中的json數組中提取特定鍵的值。我試圖從key中取出值,這些key在json數組中的任何地方都可用。下面是我使用的代碼:JSON解析與Python3.6給出問題
from xml.dom.minidom import parseString
import json
def bar(somejson, key):
def val(node):
# Searches for the next Element Node containing Value
e = node.nextSibling
while e and e.nodeType != e.ELEMENT_NODE:
e = e.nextSibling
return (e.getElementsByTagName('string')[0].firstChild.nodeValue if e
else None)
# parse the JSON as XML
foo_dom = parseString(xmlrpclib.dumps((json.loads(somejson),)))
# and then search all the name tags which are P1's
# and use the val user function to get the value
return [val(node) for node in foo_dom.getElementsByTagName('name')
if node.firstChild.nodeValue in key]
這我已經從這個問題了:How can I use python finding particular json value by key?
現在我在xmlrpclib
得到任何錯誤。我不明白爲什麼它會到來。我嘗試使用pip
獲得軟件包,但沒有可用於安裝的軟件包。
請問我該怎麼辦?數據示例與上述問題鏈接中的示例相同。
您是否正在導入'xmlrpclib'庫?順便說一句,這個庫可以在['PyPi'](https://pypi.python.org/pypi/xmlrpclib) –
@MoinuddinQuadri如何安裝它?我試圖設置,但不能或有沒有辦法在我的程序中使用它。請幫忙。 –
@JafferWilson你看到我的回答嗎?它仍然是標準庫的一部分。 – Vallentin