Android - JSON connection with different IP
<p>I am developing a android apps to get data from MySQL with JSON through php in my phone.</p>

<p>Before this, i already writen an JSON connect to get data from an web server succeed.</p>

<p>Now i already host php and MySQL server at my PC then i want to get data from it with my IP address but it did not work and throw exception.</p>

<pre><code>Error parsing data org.json.JSONException: Value 404 of type java.lang.Integer cannot be converted to JSONArray
</code></pre>

<p>However, i let my phone connect to my router with wifi and change the JSON connect IP to 192.168.XXX.XXX, it succeed to get data.</p>

<p>May i know whats happen? Is my router get wrong configure? or php host?</p>

<p>(I use WAMP to host php server)</p>

<p>Enclosed code:</p>

<p>This is my JSON code:</p>

<pre><code>String result = "";
    ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
    nameValuePairs.add(new BasicNameValuePair("sql",
            "select * from staff_table"));
    InputStream is = null;
    // http post
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://my-ip/android_getdata.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection " + e.toString());
    }
    // convert response to string
    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();

        result = sb.toString();
    } catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
    }

    // parse json data
    try {

        JSONArray jArray = new JSONArray(result);
        for (int i = 0; i &lt; jArray.length(); i++) {
            JSONObject json_data = jArray.getJSONObject(i);
            //do some here
        }
    } catch (JSONException e) {
        Log.e("log_tag", "Error parsing data " + e.toString());
    }
</code></pre>
