簡體   English   中英

在json響應中獲取元素的值

[英]getting value of element in json response

我得到的我的json響應

$str = '{"Refund_Order_Result":{"reason":"","refund_status":0}} ';
$refoutput = json_decode($str,true);

print $refoutput->Refund_Order_Result->refund_status;

我想獲取無法做到的return_status的值。 任何獲得價值的方法

echo "<pre>";print_r($refoutput);//see this is an array so use below code
echo $refoutput['Refund_Order_Result']['refund_status'];

要么

$refoutput = json_decode($str);//remove true this wil return object
echo $refoutput->Refund_Order_Result->refund_status;

注意 :如果為TRUE ,則返回的objects將轉換為associative arrays.

您使用過true,所以您得到的不是array object

$refoutput = json_decode($str,true);

上面的變量將提供一個數組,因此您必須使用下面給出的代碼...

$refoutput['Refund_Order_Result']['refund_status']
$refoutput['Refund_Order_Result']['refund_status'];

嘗試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM