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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:28:28+00:00 2026-05-17T21:28:28+00:00

I was having a question about making a 2D JSON string Now I would

  • 0

I was having a question about making a 2D JSON string

Now I would like to know why I can’t access the following:

$json_str = '{"urls":["http://example.com/001.jpg","http://example.com/003.jpg","http://example.com/002.jpg"],"alts":["testing int chars àèéìòóù stop","second description",""],"favs":["true", "false", "false"]}';

$j_string_decoded = json_decode($json_str);
// echo print_r($j_string_decoded); // OK

// test get url from second item
echo j_string_decoded['urls'][1];
// Fatal error: Cannot use object of type stdClass as array
  • 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-17T21:28:29+00:00Added an answer on May 17, 2026 at 9:28 pm

    You are accessing it with array-like syntax:

    echo j_string_decoded['urls'][1];
    

    Whereas object is returned.

    Convert it to array by specifying second argument to true:

    $j_string_decoded = json_decode($json_str, true);
    

    Making it:

    $json_str = '{"urls":["http://site.com/001.jpg","http://site.com/003.jpg","http://site.com/002.jpg"],"alts":["testing int chars àèéìòóù stop","second description",""],"favs":["true", "false", "false"]}';
    
    $j_string_decoded = json_decode($json_str, true);
    echo j_string_decoded['urls'][1];
    

    Or Try this:

    $j_string_decoded->urls[1]
    

    Notice the -> operator used for objects.

    Quoting from Docs:

    Returns the value encoded in json in
    appropriate PHP type. Values true,
    false and null (case-insensitive) are
    returned as TRUE, FALSE and NULL
    respectively. NULL is returned if the
    json cannot be decoded or if the
    encoded data is deeper than the
    recursion limit.

    http://php.net/manual/en/function.json-decode.php

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

Sidebar

Related Questions

This question is related to the post about having abstract at the titlepage. I
I know this maybe a very basic question but I'm having a bit of
I'm making a visualization for a BST implementation (I posted another question about it
I have question about the combo box. The problem I'm having is with the
I raised a question about this a while ago but I'm still having an
I have a question about equivalent search result, that can occur on different fields.
I have a question about a XNA game I'm making, but it is also
This is not a question about the names of libraries for making graphs. I
After having this question answered through a link to an external site , I
Not too practical maybe, but still interesting. Having some abstract question on matrix multiplication

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.