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?

- 322
- 2
- 10
2 Answers
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>

- 1
- 1

- 23,493
- 7
- 67
- 106
-
+1 for gson, +1 for jackson, -1 for json.org. Net +1. Lucky you! – digitaljoel Apr 26 '13 at 20:42
-
I keep getting an java.io.IOException: Server returned HTTP response code: 401 for URL: https://api.parse.com/1/classes/NicksNoteVersion/xngGDAa1k3 any ideas? – user36976 Apr 27 '13 at 06:13
-
Yes, this is due the basic authentication you need to provide, check my last comment. – Francisco Spaeth Apr 27 '13 at 07:41
You can make the http requests using standard Java API. Check here.
You can parse the response by using gson library. Check here.