1

Here is my code:

$ch = curl_init('');  

  $request = 'where={"place":"'.$place.'"}&count=1&limit=0';
  $url = "https://api.parse.com/1/classes/className" . "?" . $request;

  curl_setopt($ch, CURLOPT_URL,$url);



  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Parse-Application-Id: ...',
    'X-Parse-REST-API-Key: ...
    ));

  //curl_setopt($ch, CURLOPT_POST, true);


  // Execute
  $result = curl_exec($ch);

  // Close connection
  curl_close($ch);

Here is the output:

{"results":[],"count":0}

I want to get only he number in count.

I tried this:

$json_res = json_decode($result, true);

  echo 'Number : '.$json_res['count'];

but the output becomes:

Number :

If i do json_encode the result is just a True value.

I tried added this:

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

but didn't change anything.

What am I missing?

EDIT: doing a var_dump on $json_res gives me that: int(1). Why is that?

6
  • Did you bother checking if json_decode() actually succeeded? It returns a php null on failure. Commented Jan 11, 2014 at 22:52
  • @MarcB hmm, how to check it? Maybe it does not succeed at all. Commented Jan 11, 2014 at 22:53
  • Do a var_dump of $json_res Commented Jan 11, 2014 at 22:55
  • if ($json_res === null) { die(json_last_error()); }. Of course, this can produce a false positive if you really DID send a valid "null" value as the json string. Commented Jan 11, 2014 at 22:55
  • @AlexBarroso it prints int(1). Commented Jan 11, 2014 at 22:57

1 Answer 1

1

Curl does not return the output if you don't set the CURLOPT_RETURNTRANSFER option

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
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.