Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Json解码卷曲_Php_Json_Curl_Decode - Fatal编程技术网

Php Json解码卷曲

Php Json解码卷曲,php,json,curl,decode,Php,Json,Curl,Decode,我尝试通过PHP&curl从jsonurl获取数据。 如何解码“消息”字段? “状态”在$result->status 有人对我有什么想法吗 API JSON Format "messages": [ { "id":30, "message":"Service ID not provided!" }, { "id":32, "message":"Service does not exist." } ]

我尝试通过PHP&curl从jsonurl获取数据。 如何解码“消息”字段? “状态”在
$result->status

有人对我有什么想法吗

API JSON Format
"messages":
[
    {
        "id":30,
        "message":"Service ID not provided!"
    },
    {
        "id":32,
        "message":"Service does not exist."
    }
]

<?php
$url = 'https://www.youtube.com/watch?v=';
$quantity = '10';
$id_service = '';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.kkkkkkkkk.com/v1-api");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Incase things are slow allow enough time to try.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Can cause unexpected/no return
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);// Can cause unexpected/no return

$data = array(
    /* Required */
    'api_key' => "22",
    'action' => 'add',
    'url' => $url,
    'quantity' => $quantity,
    'id_service' => $id_service,



);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$result = json_decode(curl_exec($ch));




?>
API JSON格式 “信息”: [ { “id”:30, “消息”:“未提供服务ID!” }, { “id”:32, “消息”:“服务不存在。” } ]
编辑:答案有效,但不在我的脚本上。。知道为什么我在“消息”上没有得到响应吗?

假设$test是响应

$test = '{
    "status":"success",
    "service":"123456",
    "url":"jofNR_WkoCE",
    "long_url":"https://www.youtube.com/watch?v=",
    "message":
    [
        {
            "id":100,
            "message":"Successfully added URL"
        }
    ]
}';

$result = json_decode($test);
print_r($result->message[0]->id);

了解对象和数组之间的区别,那么这个问题就已经回答了<代码>$result->message[0]->messageTry
$result->message[0]->id
hmmm这一切都是正确的。。我已经测试了你的代码。。但是在我的脚本中它不起作用…你能再次查看我的第一篇帖子吗。。我将添加我的完整代码