package com.zhidi.zuoye;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import org.json.JSONException;
import org.json.JSONObject;
//设计一个翻译程序,
//用户在控制台输入一个英文单词,
//返回相关的翻译内容(使用json,面向对象)
public class Zuoye {
public static void main(String[] args) throws IOException, JSONException {
Scanner sc = new Scanner(System.in);
System.out.println("请输入英文单词:");
String str=sc.nextLine();
Zuoye.get(str);
}
public static void get(String code) throws IOException, JSONException{
String s=Zuoye.zxc("http://fanyi.youdao.com/openapi.do?keyfrom=youdanfanyi123&key=1357452033&type=data&doctype=json&version=1.1&q="+code);
System.out.println(s);
JSONObject obj = new JSONObject(s);
}
public static String zxc(String uri) throws IOException{
URL url = new URL(uri);
InputStream is = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
String str;
StringBuilder sb = new StringBuilder();
while ((str = br.readLine()) != null) {
sb.append(str);
}
br.close();
is.close();
return sb.toString();
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import org.json.JSONException;
import org.json.JSONObject;
//设计一个翻译程序,
//用户在控制台输入一个英文单词,
//返回相关的翻译内容(使用json,面向对象)
public class Zuoye {
public static void main(String[] args) throws IOException, JSONException {
Scanner sc = new Scanner(System.in);
System.out.println("请输入英文单词:");
String str=sc.nextLine();
Zuoye.get(str);
}
public static void get(String code) throws IOException, JSONException{
String s=Zuoye.zxc("http://fanyi.youdao.com/openapi.do?keyfrom=youdanfanyi123&key=1357452033&type=data&doctype=json&version=1.1&q="+code);
System.out.println(s);
JSONObject obj = new JSONObject(s);
}
public static String zxc(String uri) throws IOException{
URL url = new URL(uri);
InputStream is = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
String str;
StringBuilder sb = new StringBuilder();
while ((str = br.readLine()) != null) {
sb.append(str);
}
br.close();
is.close();
return sb.toString();
}
}