it my method call
if(guest){
new JsonTask().execute("URL");
}else{
new AsyncTaskGetMareker().execute();
}
This is my method:
private class JsonTask extends AsyncTask<String, String, String> {
protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line+"\n");
Log.d("Response: ", "> " + line); //here u ll get whole response...... :-)
}
return buffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result !=null){
for (int i =0; i <result.length(); i++){
JSONObject jsonObject= null;
try {
JSONObject json = new JSONObject(result);
JSONObject jsonResponse = json.getJSONObject("response");
String name = jsonResponse.getString("store_name");
String lat = jsonResponse.getString("latitude");
String lang=jsonResponse.getString("longitude");
});
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
}
This is my error
org.json.JSONException: Value [{"id":1,"store":"дом","category_id":11,"latitude":
2020-02-10 14:24:01.689 13767-13767/? W/System.err: at org.json.JSON.typeMismatch(JSON.java:112)
I found this code on this site and am trying to implement it in my project. I make sure that when checking, either a local or external file is loaded. What i do wrong in my code?Please help me...I don't understand English well, please understand and forgive me