Soporte de The Movie Database

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 respuestas (en la página 1 de 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! ;)

¿No encuentras una película o serie? Inicia sesión para crearla:

Global

s centrar la barra de búsqueda
p abrir menú de perfil
esc cierra una ventana abierta
? abrir la ventana de atajos del teclado

En las páginas multimedia

b retrocede (o a padre cuando sea aplicable)
e ir a la página de edición

En las páginas de temporada de televisión

(flecha derecha) ir a la temporada siguiente
(flecha izquierda) ir a la temporada anterior

En las páginas de episodio de televisión

(flecha derecha) ir al episodio siguiente
(flecha izquierda) ir al episodio anterior

En todas las páginas de imágenes

a abrir la ventana de añadir imagen

En todas las páginas de edición

t abrir la sección de traducción
ctrl+ s enviar formulario

En las páginas de debate

n crear nuevo debate
w cambiar el estado de visualización
p cambiar público/privado
c cambiar cerrar/abrir
a abrir actividad
r responder al debate
l ir a la última respuesta
ctrl+ enter enviar tu mensaje
(flecha derecha) página siguiente
(flecha izquierda) página anterior

Configuraciones

¿Quieres puntuar o añadir este elemento a una lista?

Iniciar sesión