I have a problem with some deprecated methods.(httpDefault)
What that i want is simple: i have url (json data) -> send request -> receive jsonObject.
i have no idea. i've already tried some tutorial, but it didn't work for me. ( 1. http://techlovejump.com/android-json-parser-from-url/ 2. https://www.youtube.com/watch?v=Fmo3gDMtp8s&list=PLsoBxH455yoZZeeza9TiG8I9dGP0zz5o9&index=4)
here is my sample code. just working with String data. (not from server data.)
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* // url : http://www.jsoneditoronline.org/?id=a31f7f816285e14991e175fccd09a561
* {
* "id":123,
* "name":abc,
* "status":"ok"
* }
*/
final String customJSON = "{\"id\":123,\"name\":abc,\"status\":\"ok\"}";
try {
JSONObject jsonObject = new JSONObject(customJSON);
int id = jsonObject.getInt("id");
String name = jsonObject.getString("name");
String status = jsonObject.getString("status");
Toast.makeText(MainActivity.this, "id #"+id+", name #"+name+", status #"+status, Toast.LENGTH_SHORT).show();
} catch (JSONException e) { e.printStackTrace(); }
}
}
please give me your tips.
how do i get JSONObject (all i have just url). url : http://www.jsoneditoronline.org/?id=a31f7f816285e14991e175fccd09a561