PHP中的JSON数据提取

PHP中的JSON数据提取,php,json,server,Php,Json,Server,我在服务器中有下面的JSON数据。如何仅提取“SUCCESS”作为PHP中的输出,其中SUCCESS是数据的对象中的状态的结果。i、 e“状态”:“成功” { "response":{ "status":true, "statusCode":"0", "statusDescription":"Amount Debited", "data":{ "balanceamount":"528", "st

我在服务器中有下面的
JSON数据。如何仅提取“
SUCCESS
”作为
PHP
中的输出,其中
SUCCESS
数据
对象
中的
状态的结果。i、 e“状态”:“成功”

{  
   "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。
但当我使用你的答案时,我得到的输出是空的。我做错了什么吗?

希望这对你有用:

对json字符串使用
json\u decode

$json= '{  
   "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"
}';


$arr = json_decode($json);

//print_r($arr);
echo $arr->response->data->status;
/*Output SUCCESS*/
die;
更新:

 $output = curl_exec ($ch); 
 $arr = json_decode($output );
 echo $arr->response->data->status;

更多信息:

到目前为止,您尝试了什么?看看下面的教程。您的答案与@pradeep有何不同?如果没有,请投票给他。感谢你的回答@Rp9,请你看看我的新编辑并帮助我。@GoGoaGone现在检查感谢你的回答@pradeep,请你看看我的新编辑并帮助我。用$output替换我答案的$json,如果$output的字符串与问题中所示的相同,那么你肯定会得到答案。你可以否决这个,但为什么否决?请解释一下,可能是因为这个问题的答案是正确的,而不是错误的。但这并不能解决我的问题。别担心,我没有投反对票,但还有其他人也回答了我的问题(我认为这解决了您最初的问题,在更新问题后,它改变了另一个问题的情况,顺便说一句,这是确定的
$output = '{  
   "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"
}';
 $json_result = json_decode($output);
echo $json_result->response->data->status;