„The Movie Database“ palaikymas

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 atsakė (on page 1 iš 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! ;)

Negalite rasti filmo ar TV laidos? Prisijunkite, kad sukurtumėte.

Bendras

s susitelkti į paieškos juostą
p profilio meniu
esc uždarykite atidarytą langą
? spartieji klavišai

Medijų puslapiuose

b grįžkite atgal (arba tėvams leidus)
e į redagavimo puslapį

TV sezono puslapiuose

(dešinė rodyklė) sekantis sezonas
(kairė rodyklė) ankstesnis sezonas

TV epizodo puslapiuose

(dešinė rodyklė) sekantis epizodas
(kairė rodyklė) ankstesnis epizodas

Visuose atvaizdžio puslapiuose

a atverti atvaizdžio pridėjimo langą

Visuose redagavimo puslapiuose

t vertimo parinktys
ctrl+ s pateikti formą

Diskusijų puslapiuose

n sukurti naują diskusiją
w perjungti peržiūros būseną
p perjungti viešasis / privatus
c perjungti uždaryti / atidaryti
a peržiūrėti aktyvumą
r atsakyti į pokalbį
l į paskutinį atsakymą
ctrl+ enter pateikti pranešimą
(dešinė rodyklė) sekantis puslapis
(kairė rodyklė) ankstesnis puslapis

Nustatymai

Norite įvertinti ar įtraukti šį elementą į sąrašą?

Prisijungti