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.
I suggest you use
json_encode()as you have several issues in your created json object string.So you know, here are a few problems in your json:
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.