I have the following code that returns a JSON:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import classes_json.JSONObject;
class Connection {
private String resultado;
private JSONObject js_object;
private JSONObject obj_kappauni1;
void conectar() throws IOException {
final String ENDERECO = "http://dwarfpool.com/eth/api?wallet=0940f5fAEF2bba7e1e6288E4bc4E9c75ee334b97";
//Passo por parametro o endereco no qual deve pegar o json
URL url = new URL(ENDERECO);
//Abro conexão usando a url do json, assim vai ser conectado
URLConnection conexao = url.openConnection();
//Ler valores da api
InputStreamReader inStreamread = new InputStreamReader(conexao.getInputStream());
//Guardar valores api em buffer
BufferedReader buffread = new BufferedReader(inStreamread);
//String que vai receber os valores gravados no buffer
while ((resultado = buffread.readLine()) != null) {
//Imprime o resultado
System.out.println(resultado);
js_object = new JSONObject(resultado);
}
//obj_kappauni1 = js_object.getJSONObject("kappauni1");
// boolean alive = js_object.getBoolean("alive");
// System.out.println(alive);
//Fecho gravação
inStreamread.close();
buffread.close();
}
}
Whenever I run the above code, it gives the following error:
{
Exception in thread "main" classes_json.JSONException: A JSONObject text must end with '}' at 1 [character 2 line 1]
at classes_json.JSONTokener.syntaxError(JSONTokener.java:505)
at classes_json.JSONObject.<init>(JSONObject.java:220)
at classes_json.JSONObject.<init>(JSONObject.java:357)
at Connection.conectar(Connection.java:33)
at Main.main(Main.java:10)
The JSON that returns is:
{
"autopayout_from": "0.100",
"error": false,
"last_payment_amount": "0.10213405",
"last_payment_date": "Wed, 23 Aug 2017 03:57:19 GMT",
"last_share_date": "Sat, 26 Aug 2017 14:38:54 GMT",
"payout_daily": false,
"payout_request": false,
"total_hashrate": 205.15,
"total_hashrate_calculated": 211.58,
"wallet": "0x0940f5fAEF2bba7e1e6288E4bc4E9c75ee334b97",
"wallet_balance": "0.09611122",
"workers": {
"kappauni1": {
"alive": true,
"hashrate": 113.0,
"hashrate_below_threshold": false,
"hashrate_calculated": 140.58,
"last_submit": "Sat, 26 Aug 2017 14:38:54 GMT",
"second_since_submit": 149,
"worker": "kappauni1"
},
"kappauni2": {
"alive": true,
"hashrate": 92.15,
"hashrate_below_threshold": false,
"hashrate_calculated": 71.0,
"last_submit": "Sat, 26 Aug 2017 14:38:20 GMT",
"second_since_submit": 183,
"worker": "kappauni2"
}
}
}