首页 \ 问答 \ 如何在PHP中以原始形式从POSTMAN application / json接收多个值“Array”(How to receive multiple values “Array” from POSTMAN application/json in raw form in PHP)

如何在PHP中以原始形式从POSTMAN application / json接收多个值“Array”(How to receive multiple values “Array” from POSTMAN application/json in raw form in PHP)

当我尝试在PHP中接收多个数组值进行验证时,我遇到了一些问题。 我有这个对象与POSTMAN原始形式, application/json

{
  "name":"create_insert_new_delivery",
  "param":{
       "email_of_shipment_owner":"hi@example.com",
       "shipment_type ":"B",
       "item_name": ["50", "60"],
       "item_weight ": ["H", "I"],
       "item_length": ["70", "90"]
 }
}

当我尝试接收$ item_name = $ this-> validateParameter('item_name',$ this-> param ['item_name'],ARRAY,true); 就像收到下面的两个字符串一样我得到了这个

**错误:**

[04-Jul-2018 13:16:58 UTC] PHP Parse错误:语法错误,意外',',期待'('在/home/osconliz/public_html/Osconlizapicall/api.php第304行

接收代码如下。

LINE 302

$email_of_shipment_owner = $this->validateParameter('email_of_shipment_owner', $this->param['email_of_shipment_owner'], STRING, true);

LINE 303

 $shipment_type = $this->validateParameter('shipment_type', $this->param['shipment_type'], STRING, true);

LINE 304

$item_name = $this->validateParameter('item_name', $this->param['item_name'], ARRAY, true);

LINE 305

 $item_weight = $this->validateParameter('item_weight', $this->param['item_weight'], ARRAY, true);

LINE 306

$item_length = $this->validateParameter('item_length', $this->param['item_length'], ARRAY, true);

但STRINGS正确收到:

public function validateParameter($fieldName, $value, $dataType, $required = true){
        switch ($dataType) {
            case BOOLEAN:
            if (!is_bool($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be boolean.');
            }
            break;
            case INTEGER:
            if (!is_numeric($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be integer.');
            }
            break;
            case STRING:
            if (!is_string($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be string.');
            }
            break;
            case ARRAY:
            if (!is_array($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be array.');
            }
            break;

            default:
            $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName);
            break;

        }

        return $value;
  }

收到后我想验证这样的数据

    if ($this->item_category == ""){

          } else {


          if ($this->item_category == "A" || $this->item_category == "B" || $this->item_category == "C" || $this->item_category == "D" || $this->item_category == "E" || $this->item_category == "F" || $this->item_category == "G" || $this->item_category == "H") {

          } else {
            $this->throwError(INVALID_DATA_TTT, "Invalid item category");
           exit();  
          }
          } 

I am having a little issue when I try to receive multiple array values in PHP for validation. I have this object with values in POSTMAN raw form, application/json :

{
  "name":"create_insert_new_delivery",
  "param":{
       "email_of_shipment_owner":"hi@example.com",
       "shipment_type ":"B",
       "item_name": ["50", "60"],
       "item_weight ": ["H", "I"],
       "item_length": ["70", "90"]
 }
}

When I try to receive $item_name = $this->validateParameter('item_name', $this->param['item_name'], ARRAY, true); like the two strings below are received I get this

**ERROR : **

[04-Jul-2018 13:16:58 UTC] PHP Parse error: syntax error, unexpected ',', expecting '(' in /home/osconliz/public_html/Osconlizapicall/api.php on line 304

The receiving code below.

LINE 302

$email_of_shipment_owner = $this->validateParameter('email_of_shipment_owner', $this->param['email_of_shipment_owner'], STRING, true);

LINE 303

 $shipment_type = $this->validateParameter('shipment_type', $this->param['shipment_type'], STRING, true);

LINE 304

$item_name = $this->validateParameter('item_name', $this->param['item_name'], ARRAY, true);

LINE 305

 $item_weight = $this->validateParameter('item_weight', $this->param['item_weight'], ARRAY, true);

LINE 306

$item_length = $this->validateParameter('item_length', $this->param['item_length'], ARRAY, true);

but the STRINGS are received properly :

public function validateParameter($fieldName, $value, $dataType, $required = true){
        switch ($dataType) {
            case BOOLEAN:
            if (!is_bool($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be boolean.');
            }
            break;
            case INTEGER:
            if (!is_numeric($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be integer.');
            }
            break;
            case STRING:
            if (!is_string($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be string.');
            }
            break;
            case ARRAY:
            if (!is_array($value)){
                $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName . ' it should be array.');
            }
            break;

            default:
            $this->throwError(VALIDATE_PARAMETER_DATATYPE, "Datatype is not valid for " . $fieldName);
            break;

        }

        return $value;
  }

After receiving I want validate data like this

    if ($this->item_category == ""){

          } else {


          if ($this->item_category == "A" || $this->item_category == "B" || $this->item_category == "C" || $this->item_category == "D" || $this->item_category == "E" || $this->item_category == "F" || $this->item_category == "G" || $this->item_category == "H") {

          } else {
            $this->throwError(INVALID_DATA_TTT, "Invalid item category");
           exit();  
          }
          } 

原文:https://stackoverflow.com/questions/51175225
更新时间:2024-03-09 06:03

最满意答案

是。

文档

contacts(联系人) :这是当主机出现问题(或恢复)时应该通知的联系人短名单。 多个联系人应该用逗号分隔。 如果您希望通知只发送给几个人并且不想配置联系人组,那么这很有用。 您必须在每个主机定义中至少指定一个联系人或联系人组。

contact_groups :这是联系人组短名称的列表,当该主机出现问题(或恢复)时应该通知联系人组的短名称。 多个联系人组应该用逗号分隔。 您必须在每个主机定义中至少指定一个联系人或联系人组。

其实 - 现在我复制,我不太确定它正确地描述答案。

你也可能想看看对象继承

但是,简短的答案仍然是肯定的


Yes.

From the documentation:

contacts: This is a list of the short names of the contacts that should be notified whenever there are problems (or recoveries) with this host. Multiple contacts should be separated by commas. Useful if you want notifications to go to just a few people and don't want to configure contact groups. You must specify at least one contact or contact group in each host definition.

contact_groups: This is a list of the short names of the contact groups that should be notified whenever there are problems (or recoveries) with this host. Multiple contact groups should be separated by commas. You must specify at least one contact or contact group in each host definition.

Actually - now that I copy that I'm not so sure it describes the answer properly.

You may also want to look at Object Inheritance.

But, the short answer is still a yes.

相关问答

更多
  • 是。 从文档 : contacts(联系人) :这是当主机出现问题(或恢复)时应该通知的联系人短名单。 多个联系人应该用逗号分隔。 如果您希望通知只发送给几个人并且不想配置联系人组,那么这很有用。 您必须在每个主机定义中至少指定一个联系人或联系人组。 contact_groups :这是联系人组短名称的列表,当该主机出现问题(或恢复)时应该通知联系人组的短名称。 多个联系人组应该用逗号分隔。 您必须在每个主机定义中至少指定一个联系人或联系人组。 其实 - 现在我复制,我不太确定它正确地描述答案。 你也可能想 ...
  • 警报是通过服务还是主机警报发出的? 可能是您的服务notification_interval设置为1小时。 Are the alerts coming through service or host alerts? It could be that your service notification_interval is set to 1 hour.
  • 连接被防火墙阻止,或者Nagios服务器不在“允许的主机”字段的nsc.ini文件中。 确保Windows防火墙上的端口以及Nagios服务器和客户端之间的任何其他网络过滤器都已打开。 The connection is getting blocked either by a firewall or your Nagios server is not in the nsc.ini file in the "allowed hosts" field. Make sure that port is open o ...
  • 所有你需要做的是升级你的NDOUtils到版本2.1.0为了得到它的工作! All you need to do is upgrade your NDOUtils to version 2.1.0 in order to get it working!
  • 看看https://github.com/opscode-cookbooks/nagios/blob/master/templates/default/services.cfg.erb#L14我想通过简单地定义那些属性就像现有的属性一样 - 只需要认识到json格式化。 Looking at https://github.com/opscode-cookbooks/nagios/blob/master/templates/default/services.cfg.erb#L14 I would guess ...
  • 基本问题是command_name值与原始/标准check_http命令冲突。 你有(至少)几个选择: 设置唯一的command_name ,例如check_http_8082 。 定义一个命令来检查作为参数传递的任意端口上的http。 例如 define command{ command_name check_http_port command_line /usr/lib64/nagios/plugins/check_http -H $HOSTADDRESS$ -p $ARG1$ } T ...
  • 这对我有用: location /pnp4nagios { alias /usr/share/pnp4nagios/html; } location ~ ^(/pnp4nagios.*\.php)(.*)$ { root /usr/share/pnp4nagios/html; include /etc/nginx/fastcgi_params; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PAT ...
  • 谢谢stevieb你让我走在正确的道路上。 这似乎工作: use Nagios::Config; use Nagios::Object::Config; use Data::Dumper; use feature 'say'; use Getopt::Long; Getopt::Long::Configure('bundling'); GetOptions( "C|config=s" => \$OPTION{'config'} ); my $objects; $objects = Nagi ...
  • 您的游戏专门针对您的master服务器: - name: Configure Nagios server hosts: master ... 因此,任务将仅针对此节点(或称为master的库存组中的多个节点)运行。 然后,您似乎对如何从您希望监视的其他服务器获取变量(在您的情况下slaves库存组中的所有内容)感到困惑。 inventory_hostname将完成它在锡上所说的内容 - 它将为您提供运行任务的服务器的主机名。 在这种情况下,只有永远是master 。 但是,你在这条线上的正确轨道: ...
  • Nagios和Ganglia被用作独立服务,为Ambari 1.7.0及更低版本提供信息。 从2.0版开始,Ambari开始使用他自己的监控服务Ambari Metrics和Ambari Alerts 。 Naglia与Ganglia的支持被取消。 Nagios and Ganglia were used as standalone services, to provide info for Ambari 1.7.0 and less. Since version 2.0, Ambari moved to ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)