Android中简单的jsonToListView  

Android获取服务器数据,最高效的就是json获取.有人还说编码必须UTF8,其实没啥关系.

例如服务器获取的数据格式

{msg:"success",
columns:["rowId","docId","docTitle","creator","createTime","otherInfo"],
rows:[
   {rowed:"1",docId:"A0912B124D1234123",docTitle:"公告1",creator:"管理员",createtime:"2012-3-28",otherInfo:""},
   {rowed:"2",docId:"A0914B124D1234123",docTitle:"公告2",creator:"业务人员",createtime:"2012-3-28",otherInfo:""}
   ]
}

然后

JSONObject jsonObject = new JSONObject(json);//转换成 JSONObject对象
String msg = jsonObject.getString(" msg ");//获取字段msg的值 
JSONArray rowsJsonArray =jsonObject.getJsonArray(" rows ");//获取 JSONArray对象rows 
int length= rowsJsonArray .length();
for (int i = 0; i < length; i++) {//遍历 rowsJsonArray 
    JSONObject   rowsJsonObject  =  rowsJsonArray .getJSONObject(i);
    String rowed = rowsJsonObject .getString(" rowed "); 
    String docId = rowsJsonObject .getString(" docId "); 
    String docTitle = rowsJsonObject .getString(" docTitle "); 
    String creator = rowsJsonObject .getString(" creator "); 
    String createtime = rowsJsonObject .getString(" createtime "); 
    String otherInfo = rowsJsonObject .getString(" otherInfo "); 
}

至于里面columns直接用下标就可以了

欢迎大佬支持本博客的发展 -- Donate --

本文链接:Android中简单的jsonToListView

转载声明:本站文章若无特别说明,皆为原创,转载请注明来源:三十岁,谢谢!^^


分享到:          
  1. 没有评论

  1. 没有通告