4

I am making a java program and I am looking for a way to check if theres a new version available I made an account on parse.com.
API: CLICK
I am working entirely on java and I am a bit new so keep it simple.
I have created a class with the version number and if the version is beta now i need a way to get these 2 values into a int and a boolean and do the rest of the proccessing. How do i take the values from parse.com class?

user36976
  • 324
  • 2
  • 10

2 Answers2

6

In the simplest way, you could use the library available at json.org for java (download here) and use a code similar to:

URL url = new URL("http://my.domain.com/data.json");
JSONTokener tokener = new JSONTokener(url.openStream());
JSONObject root = new JSONObject(tokener);

But of course you could use some other library that offers a bit more of flexibility like Gson or Jackson

A small sample for gson and jackson can be found here and here respectively.

For basic authentication you could use something like:

Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication ("usr", "pass".toCharArray()); } });

Something related here and documentation.

Also, HTTPClient is a great library for HTTP related stuff, please check it here if you are willing to.


If you are using Maven you can add the following dependency for json.org:

<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20090211</version>
</dependency>

Gson:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.2.2</version>
</dependency>

Jackson (with major version 1, but 2 is already available, check at the website):

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-core-asl</artifactId>
    <version>1.9.12</version>
</dependency>

For HTTP Client Version 4:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.2.4</version>
</dependency>
Community
  • 1
  • 1
Francisco Spaeth
  • 22,073
  • 6
  • 60
  • 101
0

You can make the http requests using standard Java API. Check here.

You can parse the response by using gson library. Check here.

Community
  • 1
  • 1
Arjun Rao
  • 657
  • 4
  • 15