jsoup uses post to query and parse json

 Using the post method to query and parse json is the easiest way to use the following method.

//导入
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import com.google.gson.Gson;


//post查询和json解析部分
String path = "http://localhost:9999/www?aaa=" + 666;
Log.i("查询 url ",path);
try {
	Document doc = Jsoup.connect(path)
			.ignoreContentType(true)
			.header("Content-Type", "application/json;charset=UTF-8")
			.post();
	Element body = doc.body();

	Gson gson = new Gson();
    //注意,解析json的时候要用 text 方法
    USDK usdk_res = gson.fromJson(body.text(), com.xxx.pos.USDK.class);

	Log.i("____json cardno::", usdk_res.cardno);

}catch(Exception e) {
	Log.i("发生异常", e.toString());
}


 

gradle:

implementation 'org.jsoup:jsoup:1.11.2'
implementation 'com.google.code.gson: gson: 2.8.0'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325300280&siteId=291194637