一个API层在返回一个JSON

一个API层在返回一个JSON

本文介绍了一个API层在返回一个JSON EN code,我发现了以下错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

API层(move_shopping_list.php):

api layer (move_shopping_list.php):

    if (!isset($_GET['i_sign_in_token'])){
    die(json_encode('Must pass in the i_sign_in_token into the url'));
}

if (!isset($_GET['itm_cd'])){
    die(json_encode('Must pass in itm_cd into the URL'));
}

if (!isset($_GET['list_id_old']) || !isset($_GET['list_id_new'])){
    die(json_encode('Must pass in the list_id_old or new value into the URL'));
}


$list = new ShoppingListItem($_GET['i_sign_in_token'], $_GET['itm_cd'], $_GET['list_id_old'], $_GET['list_id_new']);
$moveItems = $item->move_between_lists($token, $_GET['itm_cd'], $_GET['list_id_old'], $_GET['list_id_new']);

echo json_encode($moveItems);

下面是我列出的方法之间的举动我ShoppingListItem类里面

    public function move_between_lists($shopper, $new_list_id) {
    global $pd, $db;

    // todo: don't forget to update $this->ShoppingList
    $vars = array();
    $vars[] = array('i_sign_in_token', $shopper);
    $vars[] = array('itm_cd', $this->ITM_CD);
    $vars[] = array('list_id_old', $this->SHOPPING_LIST_ID);
    $vars[] = array('list_id_new', $new_list_id);

    $rows = $db->get_function_as_proc('custom.japi_shopping_list.Move_Bewteen_Lists(:i_sign_in_token, :itm_cd, :list_id_old, :list_id_new)', $vars);

    if ($rows == 'Y') {
        // Must have worked or it would have returned.
        $this->SHOPPING_LIST_ID = $new_list_id;

        return true;
    } else {
        return false;
    }


}

我不断收到这些错误,我不知道为什么..任何帮助将不胜AP preciated。

I keep getting these errors and i have no idea why.. any help would be greatly appreciated.

注意:未定义指数:在/var/www/api/move_shopping_list.php i_sign_in_token线3条公告:未定义指数:itm_cd在第7行的通知/var/www/api/move_shopping_list.php :未定义指数:list_id_old在/var/www/api/move_shopping_list.php第11行的通知:未定义指数:list_id_new在第15行的通知/var/www/api/move_shopping_list.php:未定义指数:i_sign_in_token在/ var / WWW /api/move_shopping_list.php第19行的通知:未定义指数:itm_cd在/var/www/api/move_shopping_list.php第19行的通知:未定义指数:list_id_old在/var/www/api/move_shopping_list.php第19行的通知:未定义指数:list_id_new在第19行的通知/var/www/api/move_shopping_list.php:未定义的变量:在第20行致命错误/var/www/api/move_shopping_list.php项目:调用一个成员函数move_between_lists()非对象/var/www/api/move_shopping_list.php第20行的

推荐答案

如果在$ _GET数组键不,你是明确检查这个不存在的键是否也并不是一个空字符串。其中的逻辑是错误的,你不能使用&放大器;&安培; (和),但 || (或)

If the array key in $_GET is not set, you are explicitly checking whether or not this nonexistant key is also not an empty string. The logic is wrong, you must not use && (and) but || (or).

这篇关于一个API层在返回一个JSON EN code,我发现了以下错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 11:27