Получить данные JSON по URL-адресу с помощью Android? ⇐ Android
-
Anonymous
Получить данные JSON по URL-адресу с помощью Android?
I am trying to get JSON data by parsing login url with username and password. I have tried by using below code but I can't get any responses. Please help me.
I am using HTTP Process and API level 23.
I need to parse my URL and get below Response
{ "response":{ "Team":"A", "Name":"Sonu", "Class":"First", }, "Result":"Good", } Below My code :
public class LoginActivity extends Activity { JSONParser jsonparser = new JSONParser(); TextView tv; String ab; JSONObject jobj = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); new retrievedata().execute(); } class retrievedata extends AsyncTask{ @Override protected String doInBackground(String... arg0) { // TODO Auto-generated method stub jobj = jsonparser.makeHttpRequest("http://myurlhere.com"); // check your log for json response Log.d("Login attempt", jobj.toString()); try { ab = jobj.getString("title"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ab; } protected void onPostExecute(String ab){ tv.setText(ab); } } }
Источник: https://stackoverflow.com/questions/332 ... ng-android
I am trying to get JSON data by parsing login url with username and password. I have tried by using below code but I can't get any responses. Please help me.
I am using HTTP Process and API level 23.
I need to parse my URL and get below Response
{ "response":{ "Team":"A", "Name":"Sonu", "Class":"First", }, "Result":"Good", } Below My code :
public class LoginActivity extends Activity { JSONParser jsonparser = new JSONParser(); TextView tv; String ab; JSONObject jobj = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); new retrievedata().execute(); } class retrievedata extends AsyncTask{ @Override protected String doInBackground(String... arg0) { // TODO Auto-generated method stub jobj = jsonparser.makeHttpRequest("http://myurlhere.com"); // check your log for json response Log.d("Login attempt", jobj.toString()); try { ab = jobj.getString("title"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ab; } protected void onPostExecute(String ab){ tv.setText(ab); } } }
Источник: https://stackoverflow.com/questions/332 ... ng-android
Мобильная версия