Answer the question
In order to leave comments, you need to log in
Why does the same code execute differently on the emulator and on a real Android device (encoding)?
Good afternoon.
For a very long time I wrote an application for Android and tested it on an emulator.
When I decided to test it on a real device, the application crashed.
After some time, we managed to find out that the problem is that it is not possible to get an array using JSON.
In the log when running on the emulator, I see that the answer comes as follows:
{"response":{"GeoObjectCollection":{"metaDataProperty":{"GeocoderResponseMetaData":{"request":"Vernadsky Avenue, ...
{"response":{"GeoObjectCollection":{"metaDataProperty":{"GeocoderResponseMetaData":{"request":"????? ??????, ????? ...
...format=json&geocode=Prospect%20Vernadsky, %20Moscow
String preUrl = "https://geocode-maps.yandex.ru/1.x/?format=json&geocode="
+ myObjects.get(position).getField.toString;
preUrl = preUrl.replace(" ", "%20");
URL url = new URL(preUrl);
Log.d("KSI++", url.toString());
URLConnection urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder result = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
Log.d("KSI18", result.toString());
}
try {
JSONObject jsonObject = new JSONObject(result.toString());
JSONArray jsonArray = jsonObject.getJSONObject("response").getJSONObject("GeoObjectCollection").getJSONArray("featureMember");
location = jsonArray.getJSONObject(0).getJSONObject("GeoObject").getJSONObject("Point").getString("pos");
Log.d("KSI++++", location + " EHRERERE!");
} catch (JSONException e) {
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question