Rasmus
Rasmus

Reputation: 241

URL request returns empty array (JSON, PHP)

I'm trying to fetch some data. I'm new to this PHP thing, JSON as well. When I print, it just gives me an empty array. Since I don't get any errors, I suppose everything else is fine.

  $request = new WP_Http;
  $result = $request->request($url, $data = array());
  $input = json_encode($request, true);
  print($input);

Upvotes: 1

Views: 253

Answers (1)

mario.van.zadel
mario.van.zadel

Reputation: 2949

You have to call

$input = json_encode($result, true);

instead of

$input = json_encode($request, true);

Upvotes: 3

Related Questions