小编Jay*_*See的帖子

将json变量映射到关键字

因此,我正在使用具有名为"public"的变量的API进行改造.我将如何让它像所有其他变量一样自动映射.

例:

@GET("/?filter=my_images")
void getMyImages(
        @Query("client_id") String id,
        @Query("api_key") String key,
        Callback<ImageList> callback
);
public static class Image{
    int id;
    String name;
    String distribution;
    String slug;
    // Can't do this:
    boolean public;
}

public static class ImageList{
    String status;
    List<Image> images;
}
Run Code Online (Sandbox Code Playgroud)

示例API结果(json):

{
  "status": "OK",
  "images": [
    {
      "id": 1,
      "name": "My first snapshot",
      "distribution": "Ubuntu",
      "slug": "ubuntu-12.10-x32",
      "public": true
    },
    {
      "id": 2,
      "name": "Automated Backup",
      "distribution": "Ubuntu"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

android gson retrofit

13
推荐指数
1
解决办法
5344
查看次数

使用HttpClient在"Adapter is detached"和"No wrapped connection"之间弹跳

所以当我说我在尝试运行时在这两个错误之间来回反复HttpClient.execute(HttpPost).入门IllegalStateException

public class NetMethods {
    private static HttpClient client = new DefaultHttpClient();

    public static void getStuff() {

    ArrayList<Alarm> alarms = new ArrayList<Alarm>();

    HttpPost post = HttpPostFactory.getHttpPost("GetStuff");

    StringBuilder builder = new StringBuilder();

    HttpResponse response = client.execute(post); // Exception thrown here

            ...
Run Code Online (Sandbox Code Playgroud)

另外,我的MttpPostFactory就是这个

import org.apache.http.client.methods.HttpPost;

public class HttpPostFactory {

private static final String url = "http://example.com/ExampleFolder/";

public static HttpPost getHttpPost(String s) {
    return new HttpPost(url + s);
}
}
Run Code Online (Sandbox Code Playgroud)

java android

2
推荐指数
1
解决办法
2446
查看次数

运行代码以生成静态变量

说我有这样一个类:

public class FileMethods {

private static final Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

public static void doSomething(){
}

}
Run Code Online (Sandbox Code Playgroud)

我如何正确初始化文档?这当前抛出了编译错误(未捕获的异常),因此可以在没有显式方法调用的情况下初始化doc吗?

java static

-1
推荐指数
1
解决办法
78
查看次数

标签 统计

android ×2

java ×2

gson ×1

retrofit ×1

static ×1