Reputation: 165
My PHP server doesn't accept second parameter for json_encode (and I need JSON_FORCE_OBJECT). Is there any way to achive simmilar effect as JSON_FORCE_OBJECT if server doesn't support it? Mybe you know some custom functions simmilar to json_encode?
Upvotes: 0
Views: 939
Reputation: 440
This should work, too:
$data = array(
'foo' => (object) array('bar' => 'foo'),
);
echo json_encode($data); // should output {"foo": {"bar": "foo"}}
Upvotes: 2