我之前使用过GSON,只要我的自定义对象具有相同名称的变量,它就会自动传输数据。但是,这一次,我也对该对象的名称或ID感兴趣。该对象只包含一个long。它的外观示例:
{"1":123,
"2":124,
"4":125,
"5":126,
"6":127}
如您所见,列表不一定包含所有后续ID,因此我不能只创建列表。你会如何解决这个问题?
答案 0 :(得分:2)
而不是反序列化为特定的自定义对象,只需反序列化为Map<String, Integer>
:
Type type = new TypeToken<Map<String, Integer>>(){}.getType();
Map<String, Integer> result = gson.fromJson(jsonString, type);
答案 1 :(得分:0)
使用jython:
<header id="header" class="navbar-fixed-top main-nav" role="banner">
<div class="container">
<div class="row">
<div class="col-md-12">
<!-- Logo start -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#home">
<img class="img-responsive" src="images\logo.png" alt="logo">
</a>
</div><!--/ Logo end -->
<nav class="collapse navbar-collapse clearfix" >
<ul class="nav navbar-nav navbar-right">
<li><a class="page-scroll" href="#home">Home</a></li>
<li><a class="page-scroll" href="#services">A Empresa</a></li>
<li><a class="page-scroll" href="#historia">História</a></li>
<li><a class="page-scroll" href="#about">Participações</a></li>
<li><a class="page-scroll" href="#team">Renovada</a></li>
<li><a class="page-scroll" href="#contact">Contato</a></li>
<li><a class="page-scroll" href="acervo.html" onClick="window.location='acervo.html'">Acervo</a></li>
<!--li><a class="page-scroll" href="#contact">Contact</a></li-->
</ul>
</nav><!--/ Navigation end -->
</div><!--/ Col end -->
</div><!--/ Row end -->
</div><!--/ Container end -->
</header><!--/ Header end -->
希望有所帮助。