2011-12-15 19 views
2

Dojoモバイルアプリをビルドしています。私は、内部のデータを取得することができる午前 DojoでJsonデータを表示

dojo.xhrPost({ 
     url: "diet.json", 
     handleAs: "json", 
     load: function(response) { 
      console.log(response.Introduction[0].title); 
     } 
    }); 

タイトル

で書かれたように、コードを印刷し導入後

{ 
    Introduction: 
    [ 
     { 
      title: "Introduction", 
      toolbar: "Page 1", 
      content: "cont, aabitant morbi tristique..." 
     }, 
     { 
      title: "Introduction", 
      toolbar: "Page 2", 
      content: "contesent vel nisi ipsum..." 
     } 
    ], 
    Services: 
    [ 
     { 
      title: "services", 
      toolbar: "Page 1", 
      content: "Cras adipiscing sapien nec..." 
     } 
    ] 
} 

:私のようなJSONファイルを持っています。どのように私は、最初の見出しを取得することができ、すなわち

  • はじめ
  • サービス

答えて

3

つまり、あなた応じて、各オブジェクトの最初のタイトルをしたいですか?

for (key in response) 
    console.log(key + ": " + response[key][0].title); 

もちろん、これは応答の各配列に少なくとも1つの要素があることを前提としています。空の場合は、次のようなものが必要です。

for (key in response) 
    console.log(key + ": " + 
       (response[key].length > 0 ? response[key][0].title : "empty")); 
+0

私はサービスについて知らなかったとします。どうすればサービスを受けることができますか? –

+0

@imi - 私の編集を参照してください –

関連する問題