如何在使用CURL发送消息后从响应变量中获取ErrorCode变量值?


How do I get the ErrorCode variable value from the response variable after message sending using CURL?

执行CURL后,我得到$result变量值为:

 {
    "ErrorCode": "000",
    "ErrorMessage": "Success",
    "JobId": "6878b812-766d-48a2-9dae-2b0edf2d84d4",
    "MessageData": [{
        "Number": "919730842844",
        "MessageParts": [{
            "MsgId": "919730842844-64a40d7611f94c03bea1045fdfa9bac5",
            "PartId": 1,
            "Text": "'u0027messagecontentsmstest'u0027"
        }]
    }]
  }

现在我需要检查ErrorCode == 000,那么我怎样才能得到单独的ErrorCode的值呢?

收到的响应类似JSON。

所以我想解码为json_decode:

$chk = json_decode($result);echo $嗯-> ErrorCode;

或者我们甚至可以用另一种方式,比如

$array = json_decode($result, true);echo $ array [' ErrorCode '],