multiple values in dictionary for json encod

This is the place for queries that don't fit in any of the other categories.

multiple values in dictionary for json encod

Postby iamnobody » Mon Feb 25, 2013 8:16 am

Hi,

I use json encode for a dictionary variable, but the dictionary can only have one key for one value, how can I use json encode for multiple values of the same key? Appreciate for an example.

Thank you.

Kind regards.
iamnobody
 
Posts: 4
Joined: Wed Feb 20, 2013 9:47 am

Re: multiple values in dictionary for json encod

Postby stranac » Mon Feb 25, 2013 10:03 am

iamnobody wrote:but the dictionary can only have one key for one value

The same is true for json.
You should use a list.

So instead of having:
Code: Select all
{
    key: value1,
    key: value2
}

You would have:
Code: Select all
{
    key: [value1, value2]
}
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: multiple values in dictionary for json encod

Postby iamnobody » Fri Mar 01, 2013 10:45 am

stranac wrote:
iamnobody wrote:but the dictionary can only have one key for one value

The same is true for json.
You should use a list.
......


Thanks stranac, that works well.

Cheers.
iamnobody
 
Posts: 4
Joined: Wed Feb 20, 2013 9:47 am


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests