Asked  1 Year ago    Answers:  5   Viewed   40 times

Hello every one i m amazed cause my android application was running very well on my samsung galaxy tab 2 but now i have this error on logcat.

org.json.JSONException: Value <.doctype of type java.lang.String cannot be converted to JSONObject

i've open port to fire-wall and configure mysql to remote access & phpmyadmin based on youtube video.

so i need help cause i don't know what to do !!?

i 'va see the response of provided on JSONException: Value of type java.lang.String cannot be converted to JSONObject


and i have some error like http 403



i find the solution it's about apache server configuration

<Directory "/home/domain/www">
    Options +Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    Order allow,deny
    Allow from all **here you need to change deny from all to Allow from all**
Saturday, May 29, 2021

Finally, I solved my problem using a custom json_decode method in order to clean the json string before decoding it.

function json_clean_decode($json, $assoc = false, $depth = 512, $options = 0) {
    // search and remove comments like /* */ and //
    $json = preg_replace("#(/*([^*]|[rn]|(*+([^*/]|[rn])))**+/)|([st]//.*)|(^//.*)#", '', $json);
    // search and remove all backslashes
    $json = str_replace("\","", $json);

    if(version_compare(phpversion(), '5.4.0', '>=')) {
        $json = json_decode($json, $assoc, $depth, $options);
    elseif(version_compare(phpversion(), '5.3.0', '>=')) {
        $json = json_decode($json, $assoc, $depth);
    else {
        $json = json_decode($json, $assoc);

    return $json;
Thursday, April 1, 2021

as far as I can see the problem is that you're getting the actual php file and not the result from the processing of such file.

The problem actually have NOTHING to do with android. Try typing the same address on your web-browser and you'll see this same PHP file you posted for us.

You need to configure a server to process that PHP file and return the JSON response.

Thursday, April 1, 2021

After almost searching for 3+ weeks and n+ hours of frustration, i've finally found an working solution to my problem and sharing it with people so they could benefit from it (as i was blocked from another a/c due to asking too many questions and down votes ) , in order to send your array list to your server we need to use another library and the best fit according to my need is async-http library by loop j and these are the steps to import and use the library in your program :-

1.)import the library into your project by writing this statement in your bulid.gradle(app module):-

compile ''

2.)Create the following variables in order to use them in your program:-

 AsyncHttpClient (a client to send data to your server)
    RequestPrarms (Data sent to your server for parsing and further operations )
    String url(Link to your server where actually operations occurs)

3.) Now we use these variables and run the program :-


arams.put("OrderSummary", <your array list>);
 ,params, new AsyncHttpResponseHandler() {
               public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                   //your operations on success

               public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

i hope this clears your doubts somewhat i'm still creating my php side in order to insert data in the database

Saturday, May 29, 2021


Based on the HTML response, I can tell you that this is not JSON. The response tells me that you have the incorrect URL for your web service.

You need to check your URL.

Extra Info / Previous Answer:

It looks like the simple answer is the right one - your result is not a valid JSON string. See website for details on what JSON should look like.

Check out JSON Parser Online - I find its very useful when working with JSON.

It is strange that you are requesting JSON, and it is not returning it properly - perhaps I have missed something.

Thursday, August 5, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :