How to get json data from post url

1k Views Asked by At

I have to get JSON from post url. This is my url URl: link

Result After process:

{
"success": false,
"error_code": null,
"data": {
         "transaction_status": 0
        }
 }

When I hit this url, mutiple url are calling internally after a long process JSON response will display in WebView. I need to fetch this JSON response by hit this url without showing WebView

Please anybody help me out from this problem.

thanks

4

There are 4 best solutions below

0
On

Please follow this tutorial.

http://www.androidhive.info/2012/01/android-json-parsing-tutorial/

You need to hit webservice using HttpUrlConnection class of android API and you can get the response in json string format.

0
On

http://www.itsalif.info/content/android-volley-tutorial-http-get-post-put

try this this will help any more query you can ask

2
On

Add volley to your project just add the following line.

compile 'com.mcxiaoke.volley:library-aar:1.0.0'

for get json response

private void sendRequest(){

    StringRequest stringRequest = new StringRequest(JSON_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    showJSON(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this,error.getMessage(),Toast.LENGTH_LONG).show();
                }
            });

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

private void showJSON(String json){
   // here you can get json.
}
0
On

This url provided by OP (I mean @dev_mg99) does not consist of a "Server-side" redirect.
The JSON data on the webpage appears after "Javascript" execution.


And as much as I know doing HTTP POST/GET (using any method provided in android) will be useless in this scenario as the server is returning "webpage" and "not JSON data".
(Please correct me if I am wrong. So that I get to learn something new)

The only possible solution coming to my mind is:
1) Load the above url in a WebView
2) Keep on checking whether the WebView has loaded "completely"
3) If it has loaded completely Extract the "html" text of the WebView and obtain the desired JSON text.

No idea how to code (2)... So cannot provide any code.


How I came to know that?

Step 1: Open above url in (say) google chrome. Wait for sometime and you will see that the page redirects to a webpage with following text:

{"success":false,"error_code":null,"data":{"transaction_status":0}}

which looks like a JSON string.

Step 2: Disable the JavaScript of the browser (For google chrome: Settings -> Show Advanced Settings -> Privacy... Content Settings --> Javascript... Click on "Do not allow any site to run JavaScript"

Step 3: Now, again, try to open above url in the browser... The page will not redirect anywhere.

According to which I conclude that the above url is redirected by JavaScript (Not from Server-Side)