[Java] 纯文本查看 复制代码import okhttp3.*;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
/**
* Created by zach on 3/24/17.
*/
public class JSONDownTester {
static OkHttpClient client = new OkHttpClient();
public static void main(String[] argsv) {
String url = "http://jsonplaceholder.typicode.com/posts";
try {
RequestBody requestBody = new FormBody.Builder()
.add("title", "foo")
.add("body", "bar").build();
Request request = new Request.Builder()
.url(url).post(requestBody).build();
Response response = client.newCall(request).execute();
String respJsonStr = response.body().string();
JSONParser parser = new JSONParser();
JSONObject jsonObj = (JSONObject) parser.parse(respJsonStr);
System.out.println(jsonObj.get("body"));
} catch (IOException io) {
io.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}