Parsing the PHP response

Posted by on 14-Nov-2014 08:57


Need help 

I have a PHP code which respond with below. How to parse this response in Trigger (Object Script).

Response has multiple rows and each has set of value.

  1. [{"accountID":"5813","date":"2014-11-13 20:58:30","leadID":"5","ip":"","page":"http:\/\/\/idx\/search.php?page=basic","referrer":"http:\/\/\/idx\/widgetpreview.php?widgetid=46897"},{"accountID":"5813","date":"2014-11-14 01:53:24","leadID":"5","ip":"","page":"http:\/\/\/idx\/myaccount.php?vlog=1","referrer":"http:\/\/\/idx\/thankyou.php?action=verify&"}]

PHP code

/ set up cURL
$handle = curl_init();
//echo "how are traffic";
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);

// exec the cURL request and returned information. Store the returned HTTP code in $code for later reference
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);

if ($code >= 200 || $code < 300)
$properties = json_decode($response,true);
$error = $code;

All Replies

Posted by Godfrey Sorita on 14-Nov-2014 09:27

Hi Anu,

This is a JSON response and you can learn how to parse/read it from this link.

The response you got is actually like:

        "accountID": "5813",
        "date": "2014-11-13 20:58:30",
        "leadID": "5",
        "ip": "",
        "page": "",
        "referrer": ""
        "accountID": "5813",
        "date": "2014-11-14 01:53:24",
        "leadID": "5",
        "ip": "",
        "page": "",
        "referrer": ""

And I was able to parse it from an Object Script using the code below:

var response_str = '[{"accountID":"5813","date":"2014-11-13 20:58:30","leadID":"5","ip":"","page":"http:\/\/\/idx\/search.php?page=basic","referrer":"http:\/\/\/idx\/widgetpreview.php?widgetid=46897"},{"accountID":"5813","date":"2014-11-14 01:53:24","leadID":"5","ip":"","page":"http:\/\/\/idx\/myaccount.php?vlog=1","referrer":"http:\/\/\/idx\/thankyou.php?action=verify&"}]';
var obj = JSON.parse(response_str);

rbv_api.print(obj[1]['accountID']); //Read the 2nd record's accountID field



This thread is closed