我想获取curl处理程序的数组,但我尝试了所有内容,似乎没有任何工作,这是请求:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $licenseServer);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $key_info);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
var_dump("<pre>".$result."</pre>");
var_dump("<pre>".curl_getinfo($ch, CURLINFO_HTTP_CODE)."</pre>");
curl_close($ch);
$result = json_decode($result, true);
switch (json_last_error()) {
echo....
}
if($result['valid'] == "true"){
//license is valid.
return true;
}
else {
return false;
}
var_dump将处理程序显示为字符串而不是json obj,并获取HTTP代码200,请求中的所有内容都很好,这是来自响应的var_dump:
string(484) "
array(4) {
["key"]=>
string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
["domain"]=>
string(9) "localhost"
["validip"]=>
string(3) "::1"
["product"]=>
string(14) "GrowLiker_Lite"
}
string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
int(1)
string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
bool(true)
string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
{"valid":"true","info":{"id":"1","domain":"NA","expire":"NA","status":"1","product":"GrowLiker_Lite","validip":"NA"}}
但是json_decode似乎不起作用,返回null- JSON_ERROR_SYNTAX - Syntax error, malformed JSON
。我如何解析并获取数组中的处理程序:$result['valid']