I have a JS file which generates a JSON object.
This JSON response string will be parsed in my android app after it is recievedfrom the URL of my JS file using this function.
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
where url
is the URL of the JS file from which the JSON object has to be fetched.
However, I can not figure out how to send the JSON response from my JS file.
So ,once I have created the JSON object, how am I supposed to properly return that JSON reponse from my JS file so that it can be fetched?
EDIT : I am hosting it on Amazon Web Services, so I can install whatever Web Server softare is required to perform the task on my EC2 instance
EDIT 2 The JS is basically the Google feed API returned in JSON result format,which needs to be fetched in my android app