构建 JSON 成为 Map

huangapple go评论57阅读模式
英文:

Contruct json into Map<String, Object>

问题

map.put("only", Arrays.asList("meta", "data", "thead"));
英文:

I want to construct the following json into a Map<String, Object>

{&quot;tm&quot;:&quot;3-ticker-payout-history-full-screen&quot;,&quot;r&quot;:&quot;ES&quot;,&quot;default_tab&quot;:&quot;overview&quot;,&quot;slug&quot;:&quot;alt-group&quot;,&quot;only&quot;:[&quot;meta&quot;,&quot;data&quot;,&quot;thead&quot;]}

Below is what I have so far

Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
map.put(&quot;tm&quot;, &quot;3-ticker-payout-history-full-screen&quot;);
map.put(&quot;slug&quot;, &quot;alt-group&quot;);
map.put(&quot;r&quot;, &quot;ES&quot;);
map.put(&quot;default_tab&quot;, &quot;overview&quot;);

How would I add &quot;only&quot;:[&quot;meta&quot;,&quot;data&quot;,&quot;thead&quot;] to the hashmap?

答案1

得分: 2

你可以创建一个 List&lt;String&gt;,并将 &quot;meta&quot;,&quot;data&quot;,&quot;thead&quot; 添加到列表中,然后将该 List&lt;String&gt; 添加到地图中。

英文:

You can create a List&lt;String&gt; and add &quot;meta&quot;,&quot;data&quot;,&quot;thead&quot; to the list, then add the List&lt;String&gt; to the map.

huangapple
  • 本文由 发表于 2020年9月16日 11:21:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63912626.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定