-1

我想将这种类型的 JSON 响应转换为 JavaScript 数组

下面,有我使用POST请求得到的响应

[{"ContactID":214},{"ContactID":213},{"ContactID":259},{"ContactID":280}]
4

1 回答 1

1

use

dataType:'json'

example

$.ajax({
  url: "script.php",
  type: "POST",
  data: {id : menuId},
  dataType: "json"
  success: function(data){
  }
});

then you don't need JSON.parse , you can directly access the response data.

if you want to loop through all values , you can use

  success: function(data){
      $.each(data, function (key, value) {
         for(index in value)
         {
           alert(index);
           alert(value[index]);
         }
     });
  }
于 2013-08-30T12:15:22.033 回答