Skip to content

DanGe42/http-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP JSON

Version: 0.0.1

A very simple Java library for making requests for JSON and parsing the responses.

You can download a pre-built version of the JAR at: http://files.danielge.org/http-json/http-json-0.0.1.jar

Usage example

This library is fairly straightforward to use, but here is an example.

Let's say we want to find the current location of the ISS using the Open-Notify API. We design a class structure as follows.

class ISSNowResponse {
    private long timestamp;
    private String message;

    private LatLng iss_position;

    private class LatLng {
        private double latitude;
        private double longitude;

        public Tuple<Double,Double> toTuple() {
            return new Tuple<Double, Double>(latitude, longitude);
        }
    }
}

For more information on how to construct such classes, see the GSON documentation.

To make the JSON request:

JsonResponse response = JsonRequest.get("http://api.open-notify.org/iss-now/");

To decode the JSON response, we could write something like this:

if (response.getResponseCode() == 200) {    // HTTP OK
    ISSNowResponse issNow = response.fromJson(ISSNowResponse.class);
    // ...
}

About

A simple library for making HTTP requests and decoding the JSON responses.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages