如何测试返回的json结果


How to test returned json result?

我有一个Ajax请求,它正在从我的数据库中获取数据,特别是其中的两列,company_id和people_id,我需要测试json结果的结果,我需要检查结果中是否存在特定的people_id,

这是我的Ajax请求

Ext.Ajax.request({
    url: 'system/index.php',
    method: 'POST',
    params: {
        class: 'CompanyPeople',
        method: 'secget',
        data: Ext.encode({
            people_id: Ext.getCmp('peopleGrid').selectedRecord.data.people_id
        })
    },
    success: function (response) {
    },
    failure: function () {
    }
});

我以为我可以在成功函数中执行以下代码,但它不起作用

if (data == 0) {
    Ext.MessageBox.alert('Status', 'Person is not attached to anything bud!.');
}
else {
    Ext.MessageBox.alert('Status', 'Person already attached to another company.');
}

这里还有我的php

class CompanyPeople extends Connect {
    function __construct() {
        parent::__construct();
    }
    public function secget($vars) {
        $sql = "SELECT * FROM CompanyPeople where people_id={$vars->data->people_id}";
        $data = array();
        $total = 0;
        if ($result = $vars->db->query($sql)) {
            while ($row = $result->fetch_assoc()) {
                $data[] = array("people_id" => intval($row["people_id"]));
                $total++;
            }
            $result->free();
        }
        echo json_encode(array("success" => true, "total" => $total, "topics" => $data));
    }
}

我认为这样的东西应该有效:

success: function( response ){
    if(response.success === true) {
        var personExist = false;
        for(var i = 0; i < response.topics.lenght; ++i) {
            // Your specific people_id in myValue
            if(response.topics[i]['people_id'] === myValue) {
                personExist = true;
                break;
            }
        }
    }
},