How to get JSON object from HTTP request in Java

前端 未结 4 1357
春和景丽
春和景丽 2021-01-01 04:58

I\'m now trying to get JSON Object with using HTTP request in Java cord.

I want to know how I can get response or JSON object in the following cord.

Please

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 05:48

    Sample implementation with corn-httpclient & corn-converter

    HttpClient client = new HttpClient(new URI(http://en.wikipedia.org/w/api.php?action=query&prop=categories&format=json&clshow=!hidden&cllimit=10&titles=" + words[i]));
    HttpResponse response = client.sendData(HTTP_METHOD.GET);
    if (! response.hasError()) {
    String jsonString = response.getData();
    JsTypeComplex jsonResponse =  (JsTypeComplex) JsonStringParser.parseJsonString(jsonString);
    JsTypeList resultsArr = (JsTypeList) jsonResponse.get("results");
    

    Maven dependencies:

    
        net.sf.corn
        corn-httpclient
        1.0.0
    
    
        net.sf.corn
        corn-converter
        1.0.0
    
    

提交回复
热议问题