Php 将数组传递给API

Php 将数组传递给API,php,Php,我试图将数组传递给API,当我以POSTMAN原始格式运行它时,API采用以下格式的数组 当我试图以这种格式在代码中传递数组时 $data = array( "content" => "50.150.50.55", "type" => "A", "name" => "gulpanra.mauqe.com", "prio" => "null",

我试图将数组传递给API,当我以POSTMAN原始格式运行它时,API采用以下格式的数组

当我试图以这种格式在代码中传递数组时

 $data = array(
             "content" => "50.150.50.55",
             "type" => "A",
             "name" => "gulpanra.mauqe.com",
             "prio" => "null",
             "ttl" => "3600"
             );
我不明白,有什么问题。响应称错误数据发送格式错误。plz help

使用json_encode将数组转换为json格式,然后将其传递给api

您正在使用的Api需要json格式的数据

$data = json_encode($data);
使用json_encode将数组转换为json格式,然后将其传递给api

您正在使用的Api需要json格式的数据

$data = json_encode($data);

您需要将数组转换为json格式,以便将其传递给api。使用json_编码。使用下面的代码

$array = array( "content" => "50.150.50.55", "type" => "A", "name" => "gulpanra.mauqe.com", "prio" => "null", "ttl" => "3600" );
$data = json_encode($data); // Pass this to API

希望这对您有所帮助

您需要将数组转换为json格式,以便将其传递给api。使用json_编码。使用下面的代码

$array = array( "content" => "50.150.50.55", "type" => "A", "name" => "gulpanra.mauqe.com", "prio" => "null", "ttl" => "3600" );
$data = json_encode($data); // Pass this to API

希望这能帮助您

API需要一组映射。下面是一组地图

[
    {
    "content": "50.150.50.55",
    "type": "A",
    "name": "test.mauqe.com",
    "prio": null,
    "ttl": 3600
    },
    {},
    {},
    ...
]
你经过的东西不一样。你只经过一张地图

{
         "content" => "50.150.50.55",
         "type" => "A",
         "name" => "gulpanra.mauqe.com",
         "prio" => "null",
         "ttl" => "3600"
 }
尝试将$data修改为:

$data = array();

array_push($data['records'], array(
         "content" => "50.150.50.55",
         "type" => "A",
         "name" => "gulpanra.mauqe.com",
         "prio" => "null",
         "ttl" => "3600"
));

API需要一组映射。下面是一组地图

[
    {
    "content": "50.150.50.55",
    "type": "A",
    "name": "test.mauqe.com",
    "prio": null,
    "ttl": 3600
    },
    {},
    {},
    ...
]
你经过的东西不一样。你只经过一张地图

{
         "content" => "50.150.50.55",
         "type" => "A",
         "name" => "gulpanra.mauqe.com",
         "prio" => "null",
         "ttl" => "3600"
 }
尝试将$data修改为:

$data = array();

array_push($data['records'], array(
         "content" => "50.150.50.55",
         "type" => "A",
         "name" => "gulpanra.mauqe.com",
         "prio" => "null",
         "ttl" => "3600"
));

例如,您必须在外部创建数组

您正在使用这种类型的数组进行编码

$data['records'] = array(
       'content' => '50.150.50.55',
       and so on
);
将此数组更改为

$data = array(
  'content' => '50.150.50.55',
   and so on
);

这将有助于

例如,您必须在外部创建数组

<?php
$data = array('records' => array());
$data['records'][] = array( 

                "content" => "50.150.50.55",
                "type" => "A",
                "name" => "gulpanra.mauqe.com",
                "prio" => null,
                "ttl" => 3600

        );

$json_output = json_encode( $data );
echo $json_output;
?>
您正在使用这种类型的数组进行编码

$data['records'] = array(
       'content' => '50.150.50.55',
       and so on
);
将此数组更改为

$data = array(
  'content' => '50.150.50.55',
   and so on
);

这将有助于

请发布一个更完整的代码示例,该示例显示了如何调用用于将此数据从php发送到此API服务的函数。是否忘记添加记录?你试过把3600作为一个数字而不是字符串吗?然后尝试将null作为null而不是字符串?请发布一个更完整的代码示例,说明如何调用用于将此数据从php发送到此API服务的函数。是否忘记添加记录?你试过把3600作为一个数字而不是字符串吗?然后尝试将null作为null而不是字符串?这很可能是正确的,但它也需要它作为json-完全正确…………您是对的,我已经将其转换为json,但是如何将我的数组转换为映射数组。请注意,我假设json_编码已经排序,就像OP中已经排序一样。请参阅解决方案的最后一部分,其中我建议了如何声明$data。我已经尝试过,但同样的错误…………您理解我的问题,但尝试给我正确的解决方案PLZ这很可能是正确的解决方案,但它也需要它作为json-完全正确…………您是对的,我已经将其转换为json,但是如何将我的数组转换为映射数组。请注意,我假设json_编码已经排序,就像OP中已经排序一样。请参阅解决方案的最后一部分,在那里我建议如何声明$data。我已经尝试过,但同样的错误…………您理解我的问题,但尝试给我正确的解决方案plzyou是天才Yyou是天才Y
<?php
$data = array('records' => array());
$data['records'][] = array( 

                "content" => "50.150.50.55",
                "type" => "A",
                "name" => "gulpanra.mauqe.com",
                "prio" => null,
                "ttl" => 3600

        );

$json_output = json_encode( $data );
echo $json_output;
?>