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

  • Home
  • SEARCH
  • 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 156911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:24:36+00:00 2026-05-11T10:24:36+00:00

There is a strange behaviour with json_encode and json_decode and I can’t find a

  • 0

There is a strange behaviour with json_encode and json_decode and I can’t find a solution:

My php application calls a php web service. The webservice returns json that looks like this:

var_dump($foo): string(62) '{'action':'set','user':'123123123123','status':'OK'}' 

now I like to decode the json in my application:

$data = json_decode($foo, true) 

but it returns NULL:

var_dump($data): NULL 

I use php5. The Content-Type of the response from the webservice: 'text/html; charset=utf-8' (also tried to use 'application/json; charset=utf-8')

What could be the reason?

  • 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. 2026-05-11T10:24:37+00:00Added an answer on May 11, 2026 at 10:24 am

    EDIT: Just did some quick inspection of the string provided by the OP. The small ‘character’ in front of the curly brace is a UTF-8 B(yte) O(rder) M(ark) 0xEF 0xBB 0xBF. I don’t know why this byte sequence is displayed as  here.

    Essentially the system you aquire the data from sends it encoded in UTF-8 with a BOM preceding the data. You should remove the first three bytes from the string before you throw it into json_decode() (a substr($string, 3) will do).

    string(62) '{'action':'set','user':'123123123123','status':'OK'}'             ^             |             This is the UTF-8 BOM 

    As Kuroki Kaze discovered, this character surely is the reason why json_decode fails. The string in its given form is not correctly a JSON formated structure (see RFC 4627)

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

Sidebar

Ask A Question

Stats

  • Questions 103k
  • Answers 103k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found the issue. The django admin uses view-wide DB… May 11, 2026 at 8:22 pm
  • Editorial Team
    Editorial Team added an answer Does the JAX-WS standard specify this? I would expect this… May 11, 2026 at 8:22 pm
  • Editorial Team
    Editorial Team added an answer You can use commit_manually to get full control of a… May 11, 2026 at 8:22 pm

Related Questions

There is a strange behaviour with json_encode and json_decode and I can't find a
I'm new to WPF and its Databinding, but I stumbled upon a strange behaviour
I came across a strange behaviour when doing some regular expressions in JavaScript today
I want to match a portion of a string using a regular expression and
I have been attempting to handle the KeyDown event of a UserControl (page) in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.