Sprijin Bază de date filme (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 răspunsuri (pe pagina 1 din 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! ;)

Nu găsiți un film sau un serial? Autentificați-vă pentru a-l crea.

Globale

s focalizează bara de căutare
p deschide meniul profilului
esc închide o fereastră deschisă
? deschide fereastra cu scurtături de la tastatură

Pe paginile media

b mergi înapoi (sau la părinte atunci când este cazul)
e mergi la pagina de editare

Pe paginile sezoanelor filmelor seriale

(săgeată dreapta) mergi la sezonul următor
(săgeată stânga) mergi la sezonul precedent

Pe paginile episoadelor filmelor seriale

(săgeată dreapta) mergi la episodul următor
(săgeată stânga) mergi la episodul precedent

Pe toate paginile de imagini

a deschide fereastra pentru adăugarea de imagini

Pe toate paginile de editare

t deschide selectorul de traduceri
ctrl+ s trimite formularul

Pe paginile de discuții

n crează o discuție nouă
w comută starea de vizionare
p comută publică/privată
c comută închisă/deschisă
a deschide activitatea
r răspunde la discuție
l mergi la ultimul răspuns
ctrl+ enter trimite mesajul
(săgeată dreapta) pagina următoare
(săgeată stânga) pagina precedentă

Setări

Doriți să evaluați sau să adăugați acest articol într-o listă?

Autentificare