从php中的json数据中重读longurl

时间:2018-05-09 16:00:51

标签: php json

我有一个json数据:

{ "success": true, "payment_request": { "id": "3e64d6cbe5ab4829a34845ba69e6f1bb", "phone": "+918562074512", "email": "abcd1@gmail.com", "buyer_name": "just a name", "amount": "10.00", "purpose": "Demo PAID Package", "expires_at": null, "status": "Pending", "send_sms": false, "send_email": true, "sms_status": null, "email_status": "Pending", "shorturl": null, "longurl": "https://test.instamojo.com/@justaname/3e64d6cbe5ab4829a34845ba69e6f1bb", "redirect_url": "http://www.mywebsite.in/exam/Checkouts/Instamojopostpayment/", "webhook": "http://www.example.com/webhook/", "allow_repeated_payments": false, "customer_id": null, "created_at": "2018-05-09T15:05:03.712593Z", "modified_at": "2018-05-09T15:05:03.712614Z" } } 

现在我需要在php变量中从中获取 longurl

我正在尝试提到的所有内容here ..但不知道我在做什么错误。

感谢任何帮助

3 个答案:

答案 0 :(得分:0)

只需使用json_decode()

尝试这样做
$array = json_decode($string,1); //decoding it as an array with 2nd argument 1
echo $array['payment_request']['longurl'];

DEMO: https://eval.in/1001721

答案 1 :(得分:0)

$string = '{ "success": true, "payment_request": { "id": "3e64d6cbe5ab4829a34845ba69e6f1bb", "phone": "+918562074512", "email": "abcd1@gmail.com", "buyer_name": "just a name", "amount": "10.00", "purpose": "Demo PAID Package", "expires_at": null, "status": "Pending", "send_sms": false, "send_email": true, "sms_status": null, "email_status": "Pending", "shorturl": null, "longurl": "https://test.instamojo.com/@justaname/3e64d6cbe5ab4829a34845ba69e6f1bb", "redirect_url": "http://www.mywebsite.in/exam/Checkouts/Instamojopostpayment/", "webhook": "http://www.example.com/webhook/", "allow_repeated_payments": false, "customer_id": null, "created_at": "2018-05-09T15:05:03.712593Z", "modified_at": "2018-05-09T15:05:03.712614Z" } }';
$json = json_decode($string);

echo $json->payment_request->longurl; // echo https://test.instamojo.com/@justaname/3e64d6cbe5ab4829a34845ba69e6f1bb

答案 2 :(得分:0)

payment_request-> longurl; //对象格式 $ l = json_decode($ k,true); echo $ l [' payment_request'] [' longurl']; //数组 // echo phpinfo(); ?>