0

私のサーバーの応答は次のとおりです。

{
    data : [
              {
                 name: "ADeal",
                 image: "images/adeal.png",
              },
              {
                 name: "SDeal",
                 image: "images/sdeal.png",
              }
          ]
}

次のように解析できます:var jsonObj = JSON.parse(serverResponse)。また、次のようなオブジェクトにアクセスすることも知っていました:jsonObj.data [1] .name

しかし、私の場合、プロパティ情報を変数で取得します。この例を考えてみましょう。

function dynImage(prop, el, jsonObj){
    //Here, prop contains data[1].name
    //How can i access the jsonObj and set it to el(i.e, reference of div element)

el.style.backgroundImage = url('');

}
4

0 に答える 0