键盘快捷键
高级搜索
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"]}]
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! ;)
找不到电影或节目?登录并创建它吧。
登录
注册
想给这个条目评分或将其添加到片单中?
还不是会员?
注册加入社区
Travis Bell 的回复
于 2015 年 11 月 02 日 1:53下午
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:
Dzivo 的回复
于 2015 年 11 月 06 日 12:26下午
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.
Travis Bell 的回复
于 2015 年 11 月 06 日 12:37下午
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! ;)