解决方案 »

  1.   

    简单说一下思路,首先生成一个jsonArray数组对象,遍历每个数组元素jsonObject,在对每一个jsonObject依次安装key,去对应的值
      

  2.   

    这段JSON没有key。生成不了JSONArray,我用的GSON解析的,完事了。就是麻烦点。
      

  3.   

     首先创建一个实体类,然后用Google提供的jar包Gson对象解析。代码如下:
    1:创建实体类,要用Gson解析数据封装实体类对象的时候要记住:要有一个无参的构造方法、属性的名称要和json字符串中属性名一致。
    public class Lunch { private String cateid;
    private String cateurl;
    private String catetitle;
    private String cateprice;
    public String getCateid() {
    return cateid;
    }
    public void setCateid(String cateid) {
    this.cateid = cateid;
    }
    public String getCateurl() {
    return cateurl;
    }
    public void setCateurl(String cateurl) {
    this.cateurl = cateurl;
    }
    public String getCatetitle() {
    return catetitle;
    }
    public void setCatetitle(String catetitle) {
    this.catetitle = catetitle;
    }
    public String getCateprice() {
    return cateprice;
    }
    public void setCateprice(String cateprice) {
    this.cateprice = cateprice;
    }
    public Lunch(String cateid, String cateurl, String catetitle,
    String cateprice) {
    super();
    this.cateid = cateid;
    this.cateurl = cateurl;
    this.catetitle = catetitle;
    this.cateprice = cateprice;
    }
    public Lunch() {
    super();
    // TODO Auto-generated constructor stub
    }
    @Override
    public String toString() {
    return "Lunch [cateid=" + cateid + ", cateurl=" + cateurl
    + ", catetitle=" + catetitle + ", cateprice=" + cateprice + "]";
    }

    }
    2、写一个方法解析你的json字符串,格式很固定,只要把实体类封装好就很容易完成:
    public List<Lunch> getList(){
    Log.i("log", "jinru2");
    List<Lunch> mList = new ArrayList<Lunch>();
    String string = getString();//是一个把json文件读取成字符串的方法
    Log.i("log", string);
    Gson mGson = new Gson();
    mList = mGson.fromJson(string, new TypeToken<List<Lunch>>() {
    }.getType());
    return mList;
    }
    这样只要list集合就能用了。