// URL
private final static String base_URL = "http://10.0.2.2:8080/shreemant/fetch_product.php";
RequestQueue queue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delivery);
final TextView txtName = (TextView)findViewById(R.id.txtName);
final TextView txtAddress = (TextView)findViewById(R.id.txtAddress);
queue = Volley.newRequestQueue(this);
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, base_URL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
txtName.setText(response.getString("NAME"));
txtAddress.setText(response.getString("ADDRESS"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("error", error.toString());
}
});
queue.add(request);
При вводе того же URL-адреса в safari отображается структура JSON
, отраженная моим php
скриптом. Не могу понять, почему он не работает на студии Android. Также попробовал Gson
, получил error parsing TSL header
. error Любая помощь приветствуется.
Это вывод в веб-браузере:
{"ORDER_NO":"1","NAME":"PRITESH GOYAL","PHONE":"9893291225","ADDRESS":"CHOTI GWALTOLI","ORDER_DESC":"COW GHEE - 1 KG - QT -1","AMOUNT":"500","DRIVER":"VINOD","LANDMARK":"PATEL BRIDGE"}