Take the tour ×  I'm using PHP to connect to an API and register
some info using JSON and HTTP POST but it is not going well.
That is what I do:    1. I create a JSON object with the
json_encode function:      $name = 'Mike';     $surname =
'Hans';     $fields = array('name' => json_encode($name),
'surname' => json_encode($surname));     $postData =
json_encode($flds);   2. Once i have the post data, I just
connect to the API with curl and login with oauth, but the API
responde says:  JSON text must be an object or array (but found
number, string, true, false or null, use allow_nonref to allow
this)  I have checked the allow_nonref in Google, but i could
not find anything for PHP, all I have found is for Perl. Does
anyone have any solution/advice to solve this?   share|improve
this question Why would you encode them separately, then encode
them together? –  Ignacio Vazquez-Abrams Nov 29 '11 at 6:18 add
comment  2 Answers  To follow up on @nickb's answer, please only
use one call to json_encode, it's far bett