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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:48:09+00:00 2026-06-09T23:48:09+00:00

I seemed to be stuck with JSON Decode , i dont know how to

  • 0

I seemed to be stuck with JSON Decode , i dont know how to decode the json object or maybe im doing something very wrong , iam doing :

$error_fields_structure['product_id'] = $this->input->post('product_id');
$error_fields_structure['main_product_quantity'] = $this->input->post('quantity');
$error_fields_structure = json_encode($error_fields_structure);

i pass $error_fields_structure to my view and in my java script i do:

<?php print_r(json_decode($error_fields_structure)); ?>;

i get an error in firebug and following output

 stdClass Object
(
[product_id] => 62
[product_quantity] => 65
);

but if i do

 <?php print_r(json_decode($error_fields_structure['product_id'])); ?>;

it gives me a null string and an error
how do i get particular product_id and product_quantity from json object $error_fields_structure

  • 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-09T23:48:11+00:00Added an answer on June 9, 2026 at 11:48 pm

    You can only decode a valid json string.

    <?php print_r(json_decode($error_fields_structure['product_id'])); ?>;
    

    is incorrect as $error_fields_structure[‘product_id’] is not a json string.

    Try this :

    <?php 
    $errorFieldsArr = json_decode($error_fields_structure,true);  //convert json string to array
    var_dump($errorFieldsArr['product_id']); // get element from array
     ?>
    

    or

    <?php 
    $errorFieldsArr = json_decode($error_fields_structure);  //convert json string to stdobject
    var_dump($errorFieldsArr->product_id ); // get element from object
     ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck at something that seemed easy but became a headache pretty fast: Here
I ran into what seemed a mysterious bug this morning that I feel very
My problem seemed easy at first but i got stuck. I have some containers
GenICam seemed like the best alternative, however the documentation is sparse. Thanks in advance!
This seemed to spark a bit of conversation on another question and I thought
This seemed like it should be easy, but I have had trouble getting it
I seemed to have run into a strange problem with the CCParticleSystem and the
This seemed pretty straightforward: capture a POST in Fiddler (Windows, because I find it
My script works seemed to be working perfectly well, but Eclipse 3.7.2 was telling
I saw somewhere what seemed to be nested selects, one master select on the

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.