Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6999875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:35:54+00:00 2026-05-27T20:35:54+00:00

I’m trying to decode a selenium server’s response. The server returns: {sessionId:null,status:0,value:{os:{arch:amd64,name: Windows Server

  • 0

I’m trying to decode a selenium server’s response. The server returns:

{"sessionId":null,"status":0,"value":{"os":{"arch":"amd64","name":
"Windows Server 2008 R2","version":"6.1"},"java":{"version":"1.7.0_02"},
"build":{"revision":"15105","time":"2011-12-08 09:56:25","version":"2.15.0"}},
"class":"org.openqa.selenium.remote.Response","hCode":1813953336}

and i’m trying to decode it with the following:

$json = json_decode($s->result);
echo '<pre>'.print_r($json, 1).'</pre>';

At this stage the $s object is:

Scrape Object
(
    [headers] => Array
        (
        )

    [result] => {"sessionId":null,"status":0,"value":{"os":{"arch":"amd64","name":"Windows Server 2008 R2","version":"6.1"},"java":{"version":"1.7.0_02"},"build":{"revision":"15105","time":"2011-12-08 09:56:25","version":"2.15.0"}},"class":"org.openqa.selenium.remote.Response","hCode":287101789}
    [http_code] => 200
    [error] => 
)

However when I actually paste the results into json_decode() it does it just fine? Where am I going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:35:55+00:00Added an answer on May 27, 2026 at 8:35 pm

    I would guess that $s->result is the HTML response body, and it’s not coming back as UTF-8–encoded data (so json_encode returns NULL). This is an issue on the server side, as JSON should be UTF-8–encoded. Ideally, the server would respond with a Content-Type header telling you the encoding of the response body.

    However, you can work around the issue by calling utf8_encode on the response:

    $json = json_decode(utf8_encode($s->result));
    echo '<pre>' . print_r($json, 1) . '</pre>';
    

    This will only work if the response is in ISO-8859-1. As an additional check, you may want to detect the encoding of the response using mb_detect_encoding. You can then pass the result into iconv:

    $json = json_decode(iconv($sourceEncoding, 'UTF-8', $s->result));
    echo '<pre>' . print_r($json, 1) . '</pre>';
    

    If all else fails, have a look at the output of json_last_error:

    if ($json === null) {
        var_dump(json_last_error());
    }
    

    EDIT: The error in this case was JSON_ERROR_CTRL_CHAR; the response contained a number of NUL characters, which were removed with str_replace("\0", '', $s->result).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.