2017-11-02 8 views
-3
{ 
"batchcomplete": "", 
"query": { 
    "normalized": [{ 
     "from": "india", 
     "to": "India" 
    }], 
    "pages": { 
     "14533": { 
      "pageid": 14533, 
      "ns": 0, 
      "title": "India", 
      "extract": "India, officially the Republic of India (Bh\u0101rat Ga\u1e47ar\u0101jya), is a country in South Asia. It is the seventh-largest country by area, the second-most populous country (with over 1.2 billion people), and the most populous democracy in the world. It is bounded by the Indian Ocean on the south, the Arabian Sea on the southwest, and the Bay of Bengal on the southeast." 
     } 
    } 
} 
} 

上記のjsonレスポンスでは、「14533」はページidです.pidのトリガーごとに、pageidが変更されます。ノードの赤色の「口ひげテンプレート」でその番号に動的にアクセスしたいと思います。口ひげテンプレートでは、JSONレスポンスからその番号のキーにアクセスする方法は?

答えて

0

このようにすることができます。 JSONをパースして、ページ内のキーを取得することは

var obj = JSON.parse('{"batchcomplete": "","query": {"normalized": [{ "from": "india","to": "India"}],"pages": {"14533": {"pageid": 14533,  "ns": 0, "title": "India", "extract": "India, officially the Republic of India (Bh\u0101rat Ga\u1e47ar\u0101jya), is a country in South Asia. It is the seventh-largest country by area, the second-most populous country (with over 1.2 billion people), and the most populous democracy in the world. It is bounded by the Indian Ocean on the south, the Arabian Sea on the southwest, and the Bay of Bengal on the southeast."}}}}'); 
 
console.log(Object.keys(obj.query.pages)[0]);

オブジェクト
関連する問題