第一种方式用jsoup dom
import java.io.IOException;
import org.jsoup.Jsoup;import org.jsoup.nodes.Element;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public class JsonTest {
public static void main(String[] args) throws IOException {
Element body = Jsoup
.connect(
"http://data.seeyouyima.com/today_tips?mode=3&no_page=2&page=2&parenting_info=1&size=10&v=5.5.5&platform=android&device_id=b8:98:f7:45:de:a7&mode=3&app_id=1")
.ignoreContentType(true).get().body();
String html = body.html();
JSONObject object = JSON.parseObject(html);
JSONObject parenting_data = object.getJSONObject("parenting_data");
Object name = parenting_data.get("name");
Object description = parenting_data.get("description");
System.out.println(name);
System.out.println(description);
JSONArray array = object.getJSONArray("data");
for (int i = 0; i < array.size(); i++) {
JSONObject data = array.getJSONObject(i);
System.out.println(data.get("category"));
System.out.println(data.get("icon"));
System.out.println( data.get("id"));
System.out.println(data.get("updated_date"));
}
};
}
第二种方式 OkHttpClient dom
import java.io.IOException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class JsonTest2 {
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient.Builder().build();
Request builder = new Request.Builder().url("http://data.seeyouyima.com/today_tips?mode=3&no_page=2&page=2&parenting_info=1&size=10&v=5.5.5&platform=android&device_id=b8:98:f7:45:de:a7&mode=3&app_id=1 ").get().build();
Response execute = client.newCall(builder).execute();
ResponseBody body = execute.body();
String string = body.string();
JSONObject object = JSON.parseObject(string);
JSONObject parenting_data = object.getJSONObject("parenting_data");
Object name = parenting_data.get("name");
System.out.println(name);
System.out.println(object);
JSONArray data = object.getJSONArray("data");
for (int i = 0; i < data.size(); i++) {
JSONObject jsonObject = data.getJSONObject(i);
String icon = (String)jsonObject.get("icon");
Object id = jsonObject.get("id");
System.out.println(icon);
System.out.println(id);
}
}
} ----------------------------------------------jun