I am having trouble figuring out how to get the object "legacy" if it exists from "https://api.mojang.com/users/profiles/minecraft/" + name. On some "names" the legacy isn't present, so how could I see if it exists aswell and then output that a message and if it is there and the value is "true" then to output another message. Here is my code so far. I am using a gui builder thing,
package net.parkourworld.Poket;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.parkourworld.Poket.JsonParserFromUrl.DataObject;
import net.parkourworld.Poket.JsonParserFromUrl.Item;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class Window {
protected Shell shell;
public Text name;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
Window window = new Window();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
name = new Text(shell, SWT.BORDER);
name.setBounds(20, 72, 143, 21);
Label lblUsername = new Label(shell, SWT.NONE);
lblUsername.setBounds(20, 51, 55, 15);
lblUsername.setText("Username");
Button btnCheck = new Button(shell, SWT.NONE);
btnCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
public void parseJson(String url){
try{
Reader reader = new InputStreamReader(new URL("https://api.mojang.com/users/profiles/minecraft/" + name).openStream()); //Read the json output
Gson gson = new GsonBuilder().create();
DataObject obj = gson.fromJson(reader, DataObject.class);
System.out.println(obj);
}catch(Exception e){
System.out.println(e);
}
}
private class DataObject{ //This class should match your json object structure
private int status;
private String error_message;
private List<Item> item; // This is for the inner array
@Override
public String toString() {
return status + " - " + error_message+ " (" + item + ")";
}
}
private class Item{ //This is the inner array class
public int ID;
public String Name;
@Override
public String toString() {
return ID + " - " + Name +"\n";
}
}
}
});
btnCheck.setBounds(20, 112, 75, 25);
btnCheck.setText("Check");
}
}