阅读背景:

ParseJson.java,解析结果如果没有数组名?

来源:互联网 

This is my code:

这是我的代码:

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Belal on 9/22/2015.
 */
public class ParseJSON {
    public static String[] make;
    public static String[] model;
    public static String[] sixMonthRate;

    public static final String JSON_ARRAY = "result";
    public static final String KEY_MAKE = "make";
    public static final String KEY_MODEL = "model";
    public static final String KEY_SIXMONTHRATE = "sixMonthRate";

    private JSONArray vehicle = null;

    private String json;

    public ParseJSON(String json){
        this.json = json;
    }

    protected void parseJSON(){
        JSONObject jsonObject=null;
        try {
            jsonObject = new JSONObject(json);
            vehicle = jsonObject.getJSONArray(JSON_ARRAY);

            make = new String[vehicle.length()];
            model = new String[vehicle.length()];
            sixMonthRate = new String[vehicle.length()];

            for(int i=0;i<vehicle.length();i++){
                JSONObject jo = vehicle.getJSONObject(i);
                make[i] = jo.getString(KEY_MAKE);
                model[i] = jo.getString(KEY_MODEL);
                sixMonthRate[i] = jo.getString(KEY_SIXMONTHRATE);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
import org.json.JS



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: