1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > php 成语接龙api 成语大全API接口_数据接口 - 极速数据

php 成语接龙api 成语大全API接口_数据接口 - 极速数据

时间:2019-09-07 15:28:11

相关推荐

php 成语接龙api 成语大全API接口_数据接口 - 极速数据

package api.jisuapi.chengyu;

import .URLEncoder;

import api.util.HttpUtil;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

public class Detail {

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

public static final String URL = "/chengyu/detail";

public static final String chengyu = "叶公好龙";// utf-8

public static void Get() throws Exception {

String result = null;

String url = URL + "?appkey=" + APPKEY + "&chengyu=" + URLEncoder.encode(chengyu,"utf-8");

try {

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

JSONObject json = JSONObject.fromObject(result);

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

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

} else {

JSONObject resultarr = json.optJSONObject("result");

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

String pronounce = resultarr.getString("pronounce");

String content = resultarr.getString("content");

String comefrom = resultarr.getString("comefrom");

System.out.println(name + " " + pronounce + " " + content + " " + comefrom);

if (resultarr.opt("antonym") != null) {

JSONArray antonym = resultarr.optJSONArray("antonym");

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

System.out.print(antonym.get(i) + " ");

}

}

if (resultarr.opt("thesaurus") != null) {

JSONArray thesaurus = resultarr.optJSONArray("thesaurus");

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

System.out.print(thesaurus.get(i) + " ");

}

}

System.out.println();

String example = resultarr.getString("example");

System.out.println(example);

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。