Accessing elements of JSON object without knowing the key names

后端 未结 5 1218
礼貌的吻别
礼貌的吻别 2020-11-30 10:00

Here\'s my json:

{\"d\":{\"key1\":\"value1\",
      \"key2\":\"value2\"}}

Is there any way of accessing the keys and values (in javascript)

5条回答
  •  我在风中等你
    2020-11-30 10:22

    Is this what you're looking for?

    var data;
    for (var key in data) {
       var value = data[key];
       alert(key + ", " + value);
    }
    

提交回复
热议问题