webservice小例子
发布时间:2020-12-16 22:22:10 所属栏目:安全 来源:网络整理
导读:package test;import java.io.InputStream;import java.nio.charset.Charset;import org.apache.http.HttpResponse;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpUr
package test; import java.io.InputStream; import java.nio.charset.Charset; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONObject; public class Test { public static void main(String[] args) throws Exception { HttpClient client=new DefaultHttpClient(); HttpUriRequest request=new HttpGet("http://www.weather.com.cn/adat/sk/101181701.html"); HttpResponse resp=client.execute(request); String s=EntityUtils.toString(resp.getEntity(),Charset.forName("UTF-8")); JSONObject jso=new JSONObject(s); System.out.println(jso); JSONObject wi=(JSONObject)jso.get("weatherinfo"); System.out.println(wi.get("city")); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |