如何在android中获取以下json

时间:2017-10-16 20:38:34

标签: android json retrofit

  

如何在Android中获取此json。

@Test
public void test() {
    Changes changes = new Changes(new Table(datasource, "SOME_TABLE")).setStartPointNow();

     service.doSomething();

     changes.setEndPointNow();
     // assert database changes with changes object
}
  

我没有得到这个json android如何得到它请帮帮我

2 个答案:

答案 0 :(得分:0)

首先用

创建对象

http://www.jsonschema2pojo.org/

我们将创建对象:

 package com.example;

import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Example {

@SerializedName("status")
@Expose
private Boolean status;
@SerializedName("data")
@Expose
private List<String> data = null;

public Boolean getStatus() {
return status;
}

public void setStatus(Boolean status) {
this.status = status;
}

public List<String> getData() {
return data;
}

public void setData(List<String> data) {
this.data = data;
}

}

您将从对象获取带有代码的数据:

 // Deserialize to single object.
public Example deserializeFromJson(String jsonString) {
    Gson gson = new Gson();
    Example myClass = gson.fromJson(jsonString, Example.class);
    return myClass;
}

我希望它可以帮助你解决问题!

答案 1 :(得分:0)

  

您可以像这样存档

public class Demo {



@SerializedName("status")
@Expose
private Boolean status;
@SerializedName("data")
@Expose
private List<String> data = null;

public Boolean getStatus() {
return status;
}

public void setStatus(Boolean status) {
this.status = status;
}

public List<String> getData() {
return data;
}

public void setData(List<String> data) {
this.data = data;
}

}