java接口汽车品牌_根据品牌获取所有车型示例代码

package api.jisuapi.car;

import api.util.HttpUtil;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

public class Carlist {

public static final String APPKEY = "your_appkey_here";// 你的appkey

public static final String URL = "https://api.jisuapi.com/car/carlist";

public static final int parentid = 1;// 品牌ID

public static void Get() {

String result = null;

String url = URL + "?appkey=" + APPKEY + "&parentid=" + parentid;

try {

result = HttpUtil.sendGet(url, "utf-8");

JSONObject json = JSONObject.fromObject(result);

if (json.getInt("status") != 0) {

System.out.println(json.getString("msg"));

} else {

JSONArray resultarr = json.optJSONArray("result");

for (int i = 0; i < resultarr.size(); i++) {

JSONObject obj = (JSONObject) resultarr.opt(i);

String id = obj.getString("id");

String name = obj.getString("name");

String initial = obj.getString("initial");

String parentid = obj.getString("parentid");

String depth = obj.getString("depth");

System.out.println(id + " " + name + " " + initial + " " + parentid + " " + depth);

if (obj.opt("carlist") != null) {

JSONArray carlist = obj.optJSONArray("carlist");

for (int j = 0; j < carlist.size(); j++) {

JSONObject data = (JSONObject) carlist.opt(j);

String id1 = data.getString("id");

String name1 = data.getString("name");

String fullname = data.getString("fullname");

String initial1 = data.getString("initial");

String parentid1 = data.getString("parentid");

String logo = data.getString("logo");

String salestate = data.getString("salestate");

String depth1 = data.getString("depth");

System.out.println(id1 + " " + name1 + " " + fullname + " " + initial1 + " " + parentid1

+ " " + logo + " " + salestate + " " + depth1);

if (data.opt("list") != null) {

JSONArray list = data.optJSONArray("list");

for (int x = 0; x < list.size(); x++) {

JSONObject lists = (JSONObject) list.opt(x);

String id2 = lists.getString("id");

String name2 = lists.getString("name");

String initial2 = lists.getString("initial");

String parentid2 = lists.getString("parentid");

String logo1 = lists.getString("logo");

String price = lists.getString("price");

String yeartype = lists.getString("yeartype");

String productionstate = lists.getString("productionstate");

String salestate1 = lists.getString("salestate");

String sizetype = lists.getString("sizetype");

String depth2 = lists.getString("depth");

System.out.println(id2 + " " + name2 + " " + initial2 + " " + parentid2 + " "

+ logo1 + " " + price + " " + yeartype + " " + productionstate + " "

+ salestate1 + " " + sizetype + " " + depth2);

}

}

}

}

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值