0

ajax レスポンスから、以下のようなオブジェクトを取得しました --

"highlighting":{
    "http://example.com/test1":{
        "content":["sample content 1"],
        "title":["sample title1"]},
        "http://example.com/test2":{
            "content":["sample content2"],
            "title":["sample title1"]
        }
    }
}

「http://example.com/test*」を取得する方法を教えてください。「コンテンツ」、「タイトル」をループできますが、「http://example.com/test*」には名前が関連付けられていないためです。

ありがとう!

4

2 に答える 2

0

それらは質問の鍵です..これを試してください

var data = obj["highlighting"]
for( key in data ){

    alert(key)
}
​

フィドルをチェック

于 2012-10-30T19:39:37.830 に答える
0
var obj = {"highlighting":{//first key
                           "http://example.com/test1": { //first key in first key
                               "content":["sample content 1"],
                               "title"  :["sample title1"]
                                                       },
                           "http://example.com/test2":{ //second key in first key
                               "content":["sample content2"],
                               "title":["sample title1"]
                                                      }
                          }
          }

var first;
for (var i in obj.highlighting) {
    first = obj[i];
    break;
}

フィドル

于 2012-10-30T19:40:47.457 に答える