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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:51:02+00:00 2026-06-09T01:51:02+00:00

I am trying to send a JSON file to do some testing. I have

  • 0

I am trying to send a JSON file to do some testing. I have a simple test file that creates a Multi-dimensional array. Here is the test file:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$user['Mongo'] = null; 
$user['Facebook'] = 12345;
$user['Twitter'] = null;
$user['Foursquare'] = null;
$user['Google'] = null;
$user['Name'] = "Bill Gates";
$user['Sex'] = 'M';
$user['Age'] = 26;
$user['Birthday'] = "1985-08-13";
$user['Friends'][0]['Mongo'] = null;
$user['Friends'][0]['Facebook'] = 123456;
$user['Friends'][0]['Twitter'] = null;
$user['Friends'][0]['Foursquare'] = null;
$user['Friends'][0]['Google'] = null;
$user['Friends'][0]['Name'] = "John Smith";
$user['Friends'][0]['Relationship'] = "Open";
$user['Friends'][1]['Mongo'] = null;
$user['Friends'][1]['Facebook'] = 1234567;
$user['Friends'][1]['Twitter'] = null;
$user['Friends'][1]['Foursquare'] = null;
$user['Friends'][1]['Google'] = null;
$user['Friends'][1]['Name'] = "Martina McBride";
$user['Friends'][1]['Relationship'] = "Open";

$user_json = json_encode($user);

$call = curl_init('http://MY_IP_HERE/user_login.php');

curl_setopt($call, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($call, CURLOPT_POSTFIELDS, $user_json);
curl_setopt($call, CURLOPT_RETURNTRANSFER, true);
curl_setopt($call, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: '.strlen($user_json)));

$result = curl_exec($call);
curl_close($call);

echo $result;
?>

I am trying to retrieve the file like so:

<?php
include_once('interaction_class.php');

error_reporting(E_ALL);
ini_set('display_errors', '1');

$fp = fopen('php://input', 'r');
$rawData = stream_get_contents($fp);

$user = json_decode($rawData);

if ($user['Mongo'] == null)
{
    $user_id = $interaction->new_guest($user);
}
//...Other stuff...

I am getting an error about Object of class stdCLass on my if statement line. So, I did a var_dump() and this is the result:

object(stdClass)#1 (10) 
{ 
    ["Mongo"] => NULL 
    ["Facebook"] => int(12345) 
    ["Twitter"] => NULL 
    ["Foursquare"] => NULL 
    ["Google"] => NULL 
    ["Name"] => string(15) "Bill Gates" 
    ["Sex"] => string(1) "M" 
    ["Age"] => int(26) 
    ["Birthday"] => string(10) "1985-08-13" 
    ["Friends"] => array(2) 
    { 
        [0] => object(stdClass)#2 (7) 
        { 
            ["Mongo"] => NULL 
            ["Facebook"] => int(123456)
            ["Twitter"] => NULL 
            ["Foursquare"] => NULL 
            ["Google"] => NULL 
            ["Name"] => string(10) "John Smith" 
            ["Relationship"] => string(4) "Open" 
        } 
        [1] => object(stdClass)#3 (7) 
        { 
            ["Mongo"] => NULL 
            ["Facebook"] => int(1234567) 
            ["Twitter"] => NULL 
            ["Foursquare"] => NULL 
            ["Google"] => NULL 
            ["Name"] => string(15) "Martina McBride" 
            ["Relationship"] => string(4) "Open" 
        } 
    } 
}

My questions is, why can’t I access the info after I do a json_decode() like so:

$thing['Key']

Why is it turning it decoding into an Object instead of an array?

Thanks in advance for any help!

  • 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-09T01:51:04+00:00Added an answer on June 9, 2026 at 1:51 am

    PHP function json_decode() returns objects by default: http://www.php.net/manual/en/function.json-decode.php

    If you want to work with arrays, add the boolean “true” as the optional second parameter in the function like so:

    $user = json_decode($rawData, true);
    

    This will return arrays into variable $user

    If you want to continue loading objects, instead of using $user['Mongo'] you can use $user->Mongo

    Hope this helps and good luck!

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

Sidebar

Related Questions

I am trying to send to my server a json file. The json format
I'm trying to send JSON-object form MongoDB to page with ejs template engine. Here's
am trying send an array to php file using $_POST ,still always getting an
Here is my javascript. I am trying to have jQuery send my sign in
I am trying to send some JSON data to my ASP.NET MVC3 controller action
I'm trying to send a Json array over using an AJAX call to a
I'm trying to post some very simple data to a php file using jquery
I'm trying to send a File to the Server without success. I have this
I'm trying to send a JSON request to a remote device that then returns
Using $.getJSON(); or $.post(); I'm trying to send some parameters through a page that

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.