最好的办法是使用GSON获取日期对字符串进行deserilize: 在单独的文件中创建一个类。
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class pentaho {
public QueryInfo queryInfo;
public static class QueryInfo {
public List<Result> metadata;
public static class Result {
@SerializedName("colIndex")
public String colIndexStr;
@SerializedName("colType")
public String colTypeStr;
@SerializedName("colName")
public String colNameStr;
}
}
}
在你的活动
public pentaho pentahoResult;
在你的函数。现在
private void getJson(String jsonStr){
Gson gson = new Gson();
pentahoResult = gson.fromJson(jsonStr, pentaho.class);
你可以通过每个结果,如果有一个以上的用如int我一个循环变量替换0。
String MycolIndex = pentahoResult.d.results.get(0).colIndexStr;
String MycolType = pentahoResult.d.results.get(0).colTypeStr;
String MycolName = pentahoResult.d.results.get(0).colNameStr;
玩得开心。