how to get the value from json in android -
hi getting following json pentaho server,how need date json
"queryinfo":{ "totalrows":"1" }, "resultset":[ [ "09-09-2014" ] ], "metadata":[ { "colindex":0, "coltype":"string", "colname":"dt" } ]
}
the best way use gson deserilize string: create class in separate file.
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; } } }
in activity
public pentaho pentahoresult;
in functions.
private void getjson(string jsonstr){ gson gson = new gson(); pentahoresult = gson.fromjson(jsonstr, pentaho.class);
now can go through each result if there more 1 replacing 0 loop variable int i.
string mycolindex = pentahoresult.d.results.get(0).colindexstr; string mycoltype = pentahoresult.d.results.get(0).coltypestr; string mycolname = pentahoresult.d.results.get(0).colnamestr;
have fun.
Comments
Post a Comment