試圖從json響應中提取數據。響應包含額外的方括號,可能會解決這個問題?Python如何解析出json響應對象中的值
if debug: print "add_context_object Request: " + repr(response.url)
if debug: print "add_context_object Response: " + repr(response.content)
result = json.loads(response.content)
print result
print "Starting parse..."
wrapper = result.get("RoutingObj" , result)
add_context_object
響應:
'[[{"RoutingObj": {"serialVersionUID":1,"balance":30000.0,"delinquency":null,"routeType":"Platinum"}}]]'
json.loads
回報:
[[{u'RoutingObj': {u'delinquency': None, u'balance': 30000.0, u'routeType': u'Platinum', u'serialVersionUID': 1}}]]
誤碼出指示其列表:
wrapper = result.get("RoutingObj" , result)
AttributeError: 'list' object has no attribute 'get'
謝謝,還發現在初始設置時添加索引結果工作:'結果= eval(response.content)[0] [0]'它可能不像下面的答案一樣靈活,但我沒有看到Web服務將返回多個索引的原因。 –