I want to get some json object or son array from my prestashop web service. I can get my json in browser by url with AppKey. but this request not worked in android request.my son object is null because http request can't receive it. my question is how to get this son by request in android , browsers can get it successfully.
this is my json response in browser:
{"products":[{"id":107},{"id":120},{"id":767},{"id":26},{"id":27}]}
but I can't get this json in android, or maybe my request is wrong:
public class Asyncs {
JSONParser jParser = new JSONParser();
JSONArray jsonArrays = new JSONArray();
public class GetProduct extends AsyncTask<String, String, ArrayList<String>> {
ArrayList<String> test = new ArrayList<>();
@Override
protected void onPreExecute() {
super.onPreExecute();
}
protected ArrayList<String> doInBackground(
String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest("http://MyApp-Key@elsevan.com/api/products", "GET", params);
Log.d(" Products: >>>>>>>>>> ", json.toString());
try {
for (int i = 0; i < jsonArrays.length(); i++) {
JSONObject c = jsonArrays.getJSONObject(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return test;
}
@Override
protected void onPostExecute(final ArrayList<String> result) {
}
}
}
my log:
2540-2553/? E/JSON Parser﹕ Error parsing data org.json.JSONException: End of input at character 0 of
09-03 12:43:20.444 2540-2553/? W/dalvikvm﹕ threadid=10: thread exiting with uncaught exception (group=0xa6270288)
09-03 12:43:20.444 2540-2553/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at Requests.Asyncs$GetProduct.doInBackground(Asyncs.java:61)
at Requests.Asyncs$GetProduct.doInBackground(Asyncs.java:31)
at android.os.AsyncTask$2.call(AsyncTask.java:287)