Android Studio app stopped picking up Json online from nothing

Asked

Viewed 28 times

0

I am developing an APP, where it needs to get data online via Json from an API, without making any changes it stopped working while it was working normally, I have tested on the server that this normal.

In java:

        //Consulta na API que retorna o JSON
        InputStream input = new URL(Minha_Url_Json).openStream();
        Reader reader = new InputStreamReader(input, "UTF-8");
        Scanner s = new Scanner(reader);

        //Pegando o JSON
        String json = s.nextLine();
        JSONObject jsonObj = new JSONObject(json);  //Transformando o Json em Objeto

        //Pegando item especifico do JsonObjeto
        String status = jsonObj.getString("status");
        String id = jsonObj.getString("id");

The return of the server:

{
   status: "sucess",
   id: "28937"
}

In my manifest I’ve already enabled the connection:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

The interesting thing that until yesterday was working normally, only suddenly stopped picking up and began to say that the android APP stopped.

Error in Java:

org.json.jsonexception end of input at character 1 of
  • 1

    Have you made any changes to the server or even the file?

  • No, I think I am the server since there is no error with the code or with the Json itself.

1 answer

0

I solved using:

String out = new Scanner(new URL(URL).openStream(), "UTF-8").useDelimiter("\\A").next();
        //Comparaçao de strings
        String[] array = out.split("/");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.