How do I access a JSON object using a javascript variable

后端 未结 4 1475
傲寒
傲寒 2020-12-29 09:48

What I mean by that is say I have JSON data as such:

[{\"ADAM\":{\"TEST\":1}, \"BOBBY\":{\"TEST\":2}}]

and I want to do something like this

4条回答
  •  有刺的猬
    2020-12-29 10:17

    var data = [{"ADAM":{"TEST":1}, "BOBBY":{"TEST":2}}],
        x = "ADAM";
    
    alert(data[0][x].TEST);
    

    http://jsfiddle.net/n0nick/UWR9y/

提交回复
热议问题