我在 Robospice 中使用了这个 Request 类和 Google HTTP Java client :
public class MyRequest {
@Key
private List<String> Items;
//.....
}
我用的是:
MyRequest myRequest = new MyRequest();
myRequest.setItems(data);
this.postMyRequest = new PostMyRequest(myRequest);
getSpiceManager().execute(postMyRequest, new PostMyRequestListener());
和
JsonHttpContent jsonHttpContent = new JsonHttpContent(new JacksonFactory(), this.myRequest);
HttpRequest httpRequest = getHttpRequestFactory()
.buildPostRequest(new GenericUrl(this.baseUrl), jsonHttpContent);
httpRequest.setParser(new JacksonFactory().createJsonObjectParser());
Response response = httpRequest.execute().parseAs(getResultType());
如何将根数组名称(从“Items”)更改为其他名称?
我试过 @JsonProperty("Foo")
但没有做任何事情。
最佳答案
好的,明白了。
我从 ArrayList
扩展了我的类。
public class MyRequest extends ArrayList<String> {
//.....
}
这使得根名称为空白/空(这正是我想要的)
关于android - 如何更改 Robospice/Jackson 中的根 JSON 数组元素名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22287769/