1、通过访问接口返回一组json格式的数据。
例子如下:
String aa = "{"result":"1","roleinfo":[{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E4%B8%80","grade":5,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:28:24","playerforce":"668"},{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E4%BA%8C","grade":1,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:40:09","playerforce":"210"},{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E4%B8%89","grade":1,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:40:38","playerforce":"210"},{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E5%9B%9B","grade":1,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:41:02","playerforce":"210"}]}";
解释:返回值是一个对象,里面有两个参数result和roleinfo。roleinfo的内容是json数组。
2、将字符串转换成json对象。
JSONObject bb= JSONObject.fromObject(aa);
3、再将bb中的roleinfo截出来,放进json数组中。
JSONArray cc= JSONArray.fromObject(bb.getString("roleinfo"));
4、读cc中的属性name。
String dd ="";
for(int i=0;i<cc.size();i++)
{ JSONObject dd= JSONObject.fromObject(cc.getString(i)); ee+= java.net.URLDecoder.decode(dd.getString("name"),"UTF-8")+",";//转换格式}