首先写权限
<!-- 网络权限 -->
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
引入包
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
MainActivity布局代码
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/Mlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
Http请求网络(GET)
public class Http {
String str = "http://apis.juhe.cn/cook/query?key=81d31315d7cb8a6e2aa7add264afb729&menu=%E8%A5%BF%E7%BA%A2%E6%9F%BF&rn=10";
public static String requestHttpGet(String strUrl){
try {
//创建ur
URL url = new URL(strUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//设置为get请求
connection.setRequestMethod("GET");
//超时,时间,获取数据时间
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
//获取请求码
int code = connection.getResponseCode();
//判断是否成功
if (code == HttpURLC