Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Bug on Android when we want to get json data from server which send an integer #211

Open
lamieltoch opened this issue Dec 23, 2021 · 1 comment

Comments

@lamieltoch
Copy link

Describe the bug
The bug happens on android when we want to get json data from server which send an integer

To Reproduce
Make a http get request from client, and send an integer json value from server.

Expected behavior
We expect no jsonexception raised

Screenshots
org.json.JSONException: Value 5100 of type java.lang.Integer cannot be converted to JSONArray
at org.json.JSON.typeMismatch(JSON.java:112)
at org.json.JSONArray.(JSONArray.java:98)
at org.json.JSONArray.(JSONArray.java:110)
at com.getcapacitor.JSArray.(JSArray.java:16)
at com.getcapacitor.plugin.http.HttpRequestHandler.parseJSON(HttpRequestHandler.java:312)
at com.getcapacitor.plugin.http.HttpRequestHandler.readData(HttpRequestHandler.java:239)
at com.getcapacitor.plugin.http.HttpRequestHandler.buildResponse(HttpRequestHandler.java:209)
at com.getcapacitor.plugin.http.HttpRequestHandler.request(HttpRequestHandler.java:401)
at com.getcapacitor.plugin.http.Http$1.run(Http.java:83)
at java.lang.Thread.run(Thread.java:919)

Desktop (please complete the following information):
Android emulator api 29

Smartphone (please complete the following information):
Android emulator api 29

Additional context
Add any other context about the problem here.

@lamieltoch
Copy link
Author

Hi, I the file "HttpRequestHandler.java", If I put at line 308 try {
return new JSArray(input);
}
catch(JSONException e2) {
return Integer.parseInt(input.trim());
}

It seems to work for Integer send by the server.

So may you put this piece of code in main branch of the code.

Regards

Lamiel

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant