我正在尝试从 json 数据中获取特定值。我调用 Web 服务并使用此代码
<?php
//API Url
$url = 'http://myUrl/s1services';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
'service' => 'login',
'username' => 'demo',
'password' => 'demo',
'appid' => '256'
);
//Encode the array into JSON.
$jsonData = json_encode($jsonData, JSON_PRETTY_PRINT | JSON_INVALID_UTF8_SUBSTITUTE);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Set the compression type to gzip
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_ENCODING , "utf-8");
//execute post
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
我在下面的 json 中得到响应(我不知道为什么有些字段以二进制格式返回)
> { "success":true,
> "clientID":"9J8pJsP8KKnwH69V9JL4HNLKQrbpINb4SbDVOKPPG6X2JKbvLrLoM65ATqXLKYKrH2KtH5LLTaL5KdP0K4zPLNLOK2KrH5HGL6L4",
> "objs":[
> {
> "COMPANY":"1000",
> "COMPANYNAME":"������� Demo ��",
> "BRANCH":"1000",
> "BRANCHNAME":"����� - ����",
> "MODULE":"13",
> "MODULENAME":"�������",
> "REFID":"47",
> "REFIDNAME":"����������� AE",
> "USERID":"1",
> "FINALDATE":"",
> "ROLES":"",
> "XSECURITY":"0",
> "EXPTIME":""
> } ], "ver":"5.00.520.11321", "sn":"01100313514211", "off":false, "pin":false, "appid":"256" }
我想获取 clientID 和 COMPANYNAME 值。
我怎样才能做到这一点 ?
守着一只汪