0

I am trying to parse the JSON response from PHP. How can i get values from JSON response by keys.Thanks in advance.

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'https://www.instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Api-Key: SomeKEY','X-Auth-Token: SomeToken'));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($req_data,'','&'));
curl_setopt($ch,CURLOPT_TIMEOUT,130);
$json= curl_exec($ch);
if($err=curl_error($ch)) {
  var_dump($err);
 }
 var_dump($json);
 $jsonArray= json_decode($json,true);
6
  • If your code is correct you should have a normal array in $jsonArray. Commented Mar 18, 2016 at 15:15
  • string(840) "{ "payment_request": { "id": "26afecc7796a402fbe12293745e49b99", "phone": "+918983501918", "email": "[email protected]", "buyer_name": "ganesh more", "amount": "10", "purpose": "Wifi Service", "email_status": null, "shorturl": null, "longurl":"instamojo.com/@shaikh1280/26afecc7796a402fbe12293745e49b99", "redirect_url":"172.31.254.38/wifilan/api/success.php", "webhook": "172.31.254.38/wifilan/api/postintamojo.php", "created_at": "2016-03-18T14:59:16.772Z", "modified_at": "2016-03-18T14:59:16.772Z", "allow_repeated_payments": true }, "success": true } " Commented Mar 18, 2016 at 15:22
  • this is my response array how can i parse longurl from this array using PHP. Thanks Commented Mar 18, 2016 at 15:22
  • That's not an array, that's a json string. Is that an echo of $json or $jsonArray? Commented Mar 18, 2016 at 15:23
  • It's an var_dump($json) i am getting above response array containing array i want to parse longurl value from this dynamically. Commented Mar 18, 2016 at 15:28

1 Answer 1

1
$jsonArray['payment_request']['longurl'] 

should have the long url value you are looking for.

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.