【发布时间】:2018-05-03 06:25:25
【问题描述】:
我在服务器中有以下JSON data。我如何仅提取“SUCCESS”作为PHP 中的输出,其中SUCCESS 是Status 的结果,它位于object 的object 内部。即 "status":"SUCCESS",
{
"response":{
"status":true,
"statusCode":"0",
"statusDescription":"Amount Debited",
"data":{
"balanceamount":"528",
"status":"SUCCESS",
"statuscode":"0",
"statusdescription":"Amount Debited",
"debitedamount":"2",
"orderid":"hj",
"refId":"4450"
}
},
"checksum":"23e97234820f5987189245e4216e89425472c2fe2c957749743b21d828efae67"
}
更新
$ch = curl_init(); // initiate curl
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1); // tell curl you want to post something
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); // define what you want to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$output = curl_exec ($ch); // execute
//echo "Request_Json= ".$data_string;
//echo "Response_Json=".$output;
echo $output;
这个$output 给了我上面的 JSON。
但是当我使用你的答案时,我的输出是空的。有什么我做错了吗?
【问题讨论】:
-
到目前为止你尝试过什么?看看下面的教程。 taniarascia.com/how-to-use-json-data-with-php-or-javascript