比如通过GET方法向/sp/overrides/
发送请求后,会返回一串JSON对象,如下:
{
"1": 0.5,
"2": 0.5,
"3": 0.5,
"4": 0.5
}
我用的是okHttp+moshi的方式取回得到的JSON对象,官方示例如下
private final OkHttpClient client \= new OkHttpClient();
private final Moshi moshi \= new Moshi.Builder().build();
private final JsonAdapter<Gist\> gistJsonAdapter \= moshi.adapter(Gist.class);
public void run() throws Exception {
Request request \= new Request.Builder()
.url("https://api.github.com/gists/c2a7c39532239ff261be")
.build();
try (Response response \= client.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
Gist gist \= gistJsonAdapter.fromJson(response.body().source());
for (Map.Entry<String, GistFile\> entry : gist.files.entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue().content);
}
}
}
static class Gist {
Map<String, GistFile\> files;
}
static class GistFile {
String content;
}
请问对于这种直接返回一个数字的JSON对象应该怎么命名字段呢?
以
jackson
举例