Following this question on SO I've run into a problem. This is the JSON I'm trying to parse:
{
"origin": "XX.XX.XXX.XXX"
}
Here are the important parts of my three main classes:
DDNS.java
public static void main(String[] args) throws Exception {
Net.returnIp();
System.out.println(Data.origin);
}
Net.java
static void returnIp() throws UnsupportedEncodingException, MalformedURLException, IOException {
//Ommited code, all it does is do a GET request to get response
String responseString = new Scanner(response,"UTF-8").useDelimiter("\\A").next();
Data data = new Gson().fromJson(responseString, Data.class);
}
Data.java
public class Data {
public String origin;
@Override
public String toString() {
return String.format("ip:%s", origin);
}
}
Unless I overlooked something in the answer, I'm not completely sure what I'm doing wrong, although I have a rough idea. Could someone please explain why this is happening? Thanks.