Reputation: 118
I want to pass an api a few parameters. The api documentation says that it should be passed in this way :
attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}
I am trying to achieve this in php through the following code this but its not working:
$params = array('filename' => "@" . realpath($filename),
'parent' => array('id' => $parent_id));
Upvotes: 0
Views: 706
Reputation: 4481
you need to use PHP's own StdClass
or your own class to represent JSON
objects in PHP.
this is an exact replication of the JSON
string in your question:
$att = new StdClass;
$att->name = "tigers.jpeg";
$att->parent = new StdClass;
$att->parent->id = "11446498";
as you can see when encoding it back to JSON
with PHP:
echo json_encode($att);
//outputs: {"name":"tigers.jpeg","parent":{"id":"11446498"}}
Upvotes: 1