Assistance de TMDB

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 réponses (sur la page 1 sur 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! ;)

Un film, une émission télévisée ou un artiste est introuvable ? Connectez-vous afin de créer une nouvelle fiche.

Général

s Mettre le curseur dans la barre de recherche
p Ouvrir le menu du profil
esc Fermer une fenêtre ouverte
? Ouvrir la fenêtre des raccourcis clavier

Sur les pages des médias

b Retour (ou vers le parent si faisable)
e Afficher la page de modification

Sur les pages des saisons des émissions télévisées

Afficher la saison suivante (flèche droite)
Afficher la saison précédente (flèche gauche)

Sur les pages des épisodes des émissions télévisées

Afficher l'épisode suivant (flèche droite)
Afficher l'épisode précédent (flèche gauche)

Sur toutes les pages des images / photos

a Ouvrir la fenêtre d'ajout d'image / photo

Sur toutes les pages de modifications

t Ouvrir le sélecteur de traduction
ctrl+ s Envoyer le formulaire

Sur les pages des discussions

n Créer une nouvelle discussion
w Basculer le statut de suivi
p Basculer publique / privée
c Basculer fermer / ouvrir
a Ouvrir l'activité
r Répondre à la discussion
l Afficher la dernière réponse
ctrl+ enter Envoyer votre message
Page suivante (flèche droite)
Page précédente (flèche gauche)

Paramètres

Vous souhaitez évaluer ou ajouter cet élément à une liste ?

Connexion