如何将我的Wordpress Ajax响应字符串转换为javascript数组?

问题描述 投票:-4回答:1

我正在使用ajax从数据库中获取一些术语,并且我正在尝试使用javascript中的该数组来做一些事情。问题在于数组是一个字符串。因此,我尝试对其进行JSONParse解析,但它似乎不是JSON字符串。如何将响应数组转换为javascript数组?

array(2) {
  [0]=>
  object(WP_Term)#5571 (10) {
    ["term_id"]=>
    int(44)
    ["name"]=>
    string(16) "Lichtregeltafels"
    ["slug"]=>
    string(16) "lichtregeltafels"
    ["term_group"]=>
    int(0)
    ["term_taxonomy_id"]=>
    int(44)
    ["taxonomy"]=>
    string(16) "productcategorie"
    ["description"]=>
    string(0) ""
    ["parent"]=>
    int(29)
    ["count"]=>
    int(0)
    ["filter"]=>
    string(3) "raw"
  }
  [1]=>
  object(WP_Term)#5573 (10) {
    ["term_id"]=>
    int(47)
    ["name"]=>
    string(7) "Dimmers"
    ["slug"]=>
    string(7) "dimmers"
    ["term_group"]=>
    int(0)
    ["term_taxonomy_id"]=>
    int(47)
    ["taxonomy"]=>
    string(16) "productcategorie"
    ["description"]=>
    string(0) ""
    ["parent"]=>
    int(29)
    ["count"]=>
    int(0)
    ["filter"]=>
    string(3) "raw"
  }
}
javascript
1个回答
0
投票

尝试执行此操作以了解forEach是什么


    function do_test_callback(response)
    {
        console.log(response && response.forEach);
        response.forEach(function(item){
            console.log(item);
        });
    }

© www.soinside.com 2019 - 2024. All rights reserved.