The Movie Database Support

http://docs.themoviedb.apiary.io/#reference/timezones/timezoneslist/get

how am I supposed to deserialize this.

shouldn't the JSON be something like this [{ "code" = "AS", "zones": [ "Pacific/Pago_Pago"]}]

3 replies (on page 1 of 1)

Jump to last post

Hi Dzivo,

I am not sure what language you are using but for example in Ruby if you were looking for the Canadian timezones, it would look like this:

2.1.4 :022 > require 'rest_client'
 => true

2.1.4 :023 > require 'json'
 => true

2.1.4 :024 > response = RestClient.get 'http://api.themoviedb.org/3/timezones/list?api_key=###'
 => "[{\"AD\":[\"Europe/Andorra\"]},{\"AE\":[\"Asia/Dubai\"]},...

2.1.4 :025 > json = JSON.parse(response)
 => [{"AD"=>["Europe/Andorra"]}, {"AE"=>["Asia/Dubai"]},...

2.1.4 :025 > json.select { |key, value| key['CA'] }
 => [{"CA"=>["America/St_Johns", "America/Halifax", "America/Glace_Bay",...

Thx you got me to the solution. I am using c#.

Maybe i am wrong but if you wanted to create dictionary than you should have done something like this

[ { "key1": ["value","value"], "key2":["value","value"]}]

at least thats what you get in java and c# when you serialize dictionary or a map.

if you wanted list of objects than it would be:

[{ "code" = "key", "zones": [ "value"]},{ "code" = "key", "zones": [ "value"]}]

I was able to parse it using linq and reflection. Maybe it will be usefull for someone.

public async Task<Dictionary<string, List<string>>> GetTimezonesAsync(CancellationToken cancellationToken)
    {
        var response = await client.GetAsync("timezones/list", null, cancellationToken).ConfigureAwait(false);
        var json = await response.Content.ReadAsStringAsync();

        var jObjectList = JsonConvert.DeserializeObject<List<object>>(json);

        Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();

        foreach (JObject j in jObjectList)
        {
            try
            {
                var prop = j.Properties().First();
                var name = prop.Name;
                var value = prop.Value.ToObject<List<string>>();

                dictionary.Add(name, value);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error During Timezone Deserialization: " + e.Message);
            }
        }

        return dictionary;
     }

Ya, the response could have been better structured. I just took the list from the timezone lib and converted is straight to JSON and that's what we got. Ah well, an improvement for a future v4! ;)

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login