1

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); 
4
  • Try print_r or var_dump instead of print Commented Aug 12, 2015 at 10:54
  • Have you printed out $result to see what it looks like yet? Commented Aug 12, 2015 at 10:54
  • print gives me {}, print_r gives me Array{}, var_dump gives me string(2)"{}"... I don't understand what var_dump is trying to tell me? Commented Aug 12, 2015 at 11:01
  • I have printed $result... it gives me something like this (shortened): Array ( [headers] => Array ( [server] => ZGS [date] => Wed, 12 Aug 2015 11:02:02 GMT [content-type] => text/xml;charset=utf-8 [connection] => close [set-cookie] => Array ( [0] => 2803525351=f4606535ba1c0facda8910343cc9b6d3; Path=/ [1] => JSESSIONID=6439C6713D9D9435FB1DDE14065446E6; Commented Aug 12, 2015 at 11:02

1 Answer 1

3

You have to call

$input = json_encode($result, true); 

instead of

$input = json_encode($request, true); 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! It got me closer, and I can now see the data, but the way it spits it out is quite ugly. How can I solve this?
How does the json-encoded data look like? Please post it ;-)
[CDATA[23 Apr-2015]]\u003E\u003C\/FL\u003E\u003CFL val=\"Oprettet af\"\u003E\u003C![CDATA[(employee name)(092)]]\u003E\u003C\/FL\u003E\u003C\/row\u003E\u003Crow no=\"3\"\u003E\u003CFL val=\"JOBOPENINGID\"\u003E\u003C!
I understand an issue is that there are æøå characters in the data and fields. I tried utf8_encode but no luck

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.