Moshi HashMap反序列化器 [英] Moshi HashMap deserializer

查看:120
本文介绍了Moshi HashMap反序列化器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否可以将数组反序列化为具有json的hashMap:

I don't know if it is possible to deserialise arrays into hashMap i have got json :

"additionalProperties": [
{
  "$type": "Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities",
  "category": "Description",
  "key": "TerminalName",
  "sourceSystemKey": "BikePoints",
  "value": "200017",
  "modified": "2016-05-19T12:02:39.82"
}
........
]

对于那个json我有列表:

and for that json i have got list :

private List<AdditionalProperties> additionalProperties;

一切正常,但是如何将json存储在Key为"key"(TerminalName)"的HashMap中

everything works perfect but how store that json in HashMap where Key is "key" (TerminalName)"

private HashMap<String,AdditionalProperties> additionalProperties;

推荐答案

Moshi支持声明为Map但不声明为HashMap的字段.这样,Moshi可以对Map使用不同的实现,该实现比HashMap更适合解码的JSON.如果您将字段的类型更改为Map<String,AdditionalProperties>,它将起作用.

Moshi supports fields declared as Map but not as HashMap. This way Moshi can use a different implementation of Map that’s more appropriate than HashMap for decoded JSON. If you change your field’s type to Map<String,AdditionalProperties> it should work.

这篇关于Moshi HashMap反序列化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆