2014-09-19 67 views
0

嗨值正在以下JSON Pentaho服务器,我是如何从这个JSON如何从JSON在Android的

"queryInfo":{ 
    "totalRows":"1" 
}, 
"resultset":[ 
    [ 
     "09-09-2014" 
    ] 
], 
"metadata":[ 
    { 
     "colIndex":0, 
     "colType":"String", 
     "colName":"dt" 
    } 
] 

}

回答

0

最好的办法是使用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; 

玩得开心。