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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:24:08+00:00 2026-05-23T13:24:08+00:00

I never worked with JSON and I really need to do it now, I’ve

  • 0

I never worked with JSON and I really need to do it now, I’ve tried bunch of examples from jQuery page but it does not seem to work for me.

I have *.php file that is generating string, as I understand this is how I pass JSON to javascript from PHP. The string that I want to generate is very simple:

foreach ($imageList as $img)
{
    echo "{ thumb: 'media/img/t/$img', image: 'media/img/m/$img'},";
}

So the result would be something like (formatted)

{
thumb: 'media/img/t/123.jpg',
image: 'media/img/m/123.jpg'
},
{
thumb: 'media/img/t/1234.jpg',
image: 'media/img/m/1234.jpg'
},

and so on…

Somehow I think this is not the correct way of doing things, excuse me of course, but as I told I never worked with JSON format and I barely know what it even stands for.

I want this data to be located in javascript array so I can use it in my gallery like here (3. Using JSON) http://galleria.aino.se/docs/1.2/references/data/

Can someone help me with this one? I know that it is probably very easy problem, but for me as a total noob it is hard to understand. When I do know how to solve this I will probably understand how it works and how to use it, but now I really have no clue.

  • 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-23T13:24:08+00:00Added an answer on May 23, 2026 at 1:24 pm

    I suggest you use json_encode() as you have several issues in your created json object string.

    <?php
    
    $json_image_list = array();
    foreach ($imageList as $img){
        $json_image_list[] = array(
            'thumb' => "media/img/t/$img",
            'image' => "media/img/m/$img",
        );
    }
    
    echo json_encode($json_image_list);
    
    ?>
    

    So you know, here are a few problems in your json:

    1. An array has to be in brackets (‘[‘ & ‘]’).
    2. Your object properties must be wrapped in double quotes.

    Also, see the bottom of JSON.org for packages that are already written for the languages you’ll be using on the web so you don’t have to write your own.

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

Sidebar

Related Questions

I've never worked with Database Functions, but my current project requires it. I need
Never worked with Sharepoint, but need to add a WebPart to display a PDF
I have never worked on jquery but after some googling and learning I have
I might be an exception here but I have never worked on a team
I've never worked with JSON before and it's not going well... I have a
I am java developer, (using Spring-MVC) never worked much on javascript, But I would
As a developer who's never worked in Agile specifically (but have worked in TDD
I've never worked with any version control systems before. Now I'm trying to learn
I've never really cached data before, but I feel as though it will greatly
Sorry about this question but i never worked with SQLite, and i gone through

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.