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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:50:28+00:00 2026-06-07T13:50:28+00:00

So I am trying to make a JSON object that should hold some information

  • 0

So I am trying to make a JSON object that should hold some information about some questions for me. This is a pseudo-code of how I want it to be presented:

{
 "page" : 1,
 "info" :
          {
           "id" : 1,
           "type" : 3,
           "description": "How to do JSON?",
           "alternatives" : 
                           {
                            "id" : 1,
                            "description" : "Dunno"
                           }
                           {
                            "id" : 2,
                            "description" : "Let me show you"
                           }
                           { 
                            "id" : 3,
                            "description" : "I refuse to show you"
                           }
           }
           "id" : 2,
           "type" : 1,
           "description": "Do you get it?",
           "alternatives" : 
                           {
                            "id" : 1,
                            "description" : "Yes"
                           }
                           {
                            "id" : 2,
                            "description" : "No"
                           }
           }
}

So the code underneath is from Nightmare (one of the answers), and it does exactly what I want to do with the page and the questions, but I can’t seem to figure out how to connect alternatives to each question. You can see a snippet at the bottom where I have tried but it’s not correctly spelled and I’ve been hammering at this for a while now.

$before_json_encode[$row['page']][] = array(
  'id' => $row['id'],
  'type' => $row['type'],
  'description' => $row['description'],
  'alternatives' => $alternativesarray//im not sure about here,dont know the structure of the alternative array
);

Another illustration on how I want the hierarchy of the JSON data to appear. I need to be able to pick for instance: All alternatives to all questions on a specific page. So if I want to generate page 3 in my poll I can first find the questions within the page 3 sub-array, and then again from each question gain access to all of it’s connected alternatives in that questions’s own sub-array. Sorry for the poor explanation of my issue, it’s just a bit complicated :/

Page
 Question
  Alternative
  Alternative
  Alternative
 Question
  Alternative
  Alternative
  Alternative
 Question
  Alternative
  Alternative
Page
 Question
  Alternative
  Alternative
 Question
  Alternative
  Alternative

Update: 3rd layer:

$rows_test2[$r['page']]
['id' => $r['id'],
'type' => $r['type'],
'description' => $r['description']]
[] =
        array (
        'altid' => $t['altid'],
        'altdesc' => $t['altdesc']);
  • 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-07T13:50:29+00:00Added an answer on June 7, 2026 at 1:50 pm
    $rows[] = array(
        "page" => 1,
        "info" => array(
            "id" => 1,
            "type" => 3,
            "description" => 'desc',
        )
    );
    echo json_encode($rows); // [{"page":1,"info":{"id":1,"type":3,"description":"desc"}}]
    

    Update:

    $alternativesarray[]=array('id'=>'1', 'description'=>'yes');
    $alternativesarray[]=array('id'=>'2', 'description'=>'no');
    $rows[] = array(
        "page" => 1,
        "info" => array(
            "id" => 2,
            "type" => 3,
            "description" => 'desc',
            "alternatives" => $alternativesarray
        )
    ); 
    print json_encode($rows); // [{"page":1,"info":{"id":2,"type":3,"description":"desc","alternatives":[{"id":"1","description":"yes"},{"id":"2","description":"no"}]}}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to make this work for some time now, but I think
I'm trying to process some JSON into a Java object using some beans and
I am trying to make Django view that will give JSON responce with earliest
I'm trying to POST some json to a web service that accepts json. The
I am trying to make my WCF service method to return JSON-object, but it
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I'm trying to make an API for my rails application using JSON responses to
I'm trying to make a RESTful API with rails. When I try http://localhost:3000/api/v1/projects.json?token=kS8xi7YzaUDEmbmi9XL6 I
Trying to make a custom :confirm message for a rails form that returns data
Trying to make a simple program to catalogue books. Something like this, for example:

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.