2016-08-19 67 views
0

我從elasticsearch生成了一個奇怪的JSON文件(我認爲?)。使用_attribute獲取JSON數組的值

我想知道如果有誰知道我可以從一個JSON對象檢索數據看起來像這樣:

u'hits : { 
     u'hits : [{ 
       u'_score' : 2.1224, 
       u'_source' : {u'content': u'SomethingSomething' } 
        }], 
     u'total: 8 } 
u'took: 2 } 

我可以寫{{results.hits.hits.total}}檢索總量,然而,屬性名稱「_score」前面的下劃線符號(_)使得不可能檢索該屬性的值。

有什麼建議嗎?

+0

results.hits.hits是一個數組,你認爲呢?你如何嘗試檢索_score字段? – Sylwit

+0

{分數%中的結果%},然後{{results.hits.hits.score。但是這沒有任何回報。如果我嘗試results.hits.hits._score,我得到一個TemplateSyntaxError。 @Sylwit – Simen

+0

你沒有得到你陣列的第一項。在{{results.hits.hits [0] ._ score}}下方看到@mQuixaba響應}'[0]是你忘記的 – Sylwit

回答

0

嘗試:

{{ results.hits.hits[0]._score }} 
{{ results.hits.hits[0]._source }}