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 7867559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:44:33+00:00 2026-06-03T00:44:33+00:00

I have a JSON object im decoding from a url like so: $var =

  • 0

I have a JSON object im decoding from a url like so:

    $var = json_decode(file_get_contents($url), true);

The data i am getting is from the new battle.net API that is returned as a JSON object containing character data.

  • Here is an actual link where the character is found and there is data to be generated: Character Found.
  • Now here is a link for a character that does not exist and generates and error: Character Not Found.

Errors are returned as JSON objects that contain “status” and “reason” attributes. The value of the “status” attribute will always be “nok”.

My problem is when the character is NOT FOUND the JSON object $var is NULL where if it is FOUND the JSON object $var contains the correct data. I need to be able to check whether the status is “nok” so i can output the apropriate error message

I have:

  • Checked the links to make sure they are generating correctly.
  • Changed json_decode(file_get_contents($url), true) to: json_decode(file_get_contents($url), false) and tried accessing $var as an object.
  • Tried using cURL instead of file_get_contents($url)

I posted on the battle.net API forums but i thought i would try here as well.

  • 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-06-03T00:44:34+00:00Added an answer on June 3, 2026 at 12:44 am

    It’s because the page Character Not Found page returns a 404 Not Found HTTP response code, which makes a lot of sense, but is considered an error.

    File functions, such as file_get_contents, will return false by default when encountering an error (404, 500, etc.) on a HTTP stream wrapper.

    In order to ignore the error and return the content anyway, so that json_decode can parse it, you need to use a context:

    $context = stream_context_create(array(
        'http' => array('ignore_errors' => true),
    ));
    
    $var = json_decode(file_get_contents($url, false, $context), true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a json object returned from a third party api, it looks like:
If i have a JSON Object var Obj = { col1 : 'data' };
I am pulling data from a json and decoding it via json_decode. Here is
I have JSON object inside variable like this: var chessPieces = { p-w-1 :
I have a JSON Object that is returned from a web service call that
hello all i have one json object like {event1:{title:My birthday,start:12\/27\/2011 10:20 ,end:12\/27\/2011 00:00 },event2:{title:My
So I have a json object which has a structure like so: { John
I have JSON Object that looks something like the below object, this object can
I have an json Object like this. {'01/19/2012': Array[1],'02/19/2012': Array[7],'03/19/2012': Array[6]} Now i want
I have a JSON object that looks like this. [ { id : 23,

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.