简体   繁体   中英

how to decode encoded json data from php in phonegap android

I want to store table data from the server to android local storage. but the issue is the table data might content special character like '<' or '>' even both. So when ajax call is made i all ways get the sqllite error code 13 while inserting the data from the server. And if i try to store simple to localStorage from the server it working perfectly. So i tried to encode the data in php and then send the data to android app in json form.But know it get blank data in the ajax data. Here is the PHP code to encode data:

$select_table = 'select * from users';
$resultTableData = $conn->query($select_table);
while ($row1 = $resultTableData->fetch()) {
    $temporarydata[] = htmlentities(utf8_encode($row1),ENT_QUOTES);
}   
$data[$row] = $temporarydata;
mysql_close($con);
require_once('JSON.php');
$json = new Services_JSON();
echo ($json->encode($data));

Here is the ajax code in PhoneGap Android:

$.ajax({
    url: urlServer + 'getDynamicFormData.php',
    contentType: 'application/json',
    beforeSend: function() {
        $.mobile.loading('show');
    },
    complete: function() {
        console.log("ajax complete");
        createTable();
    },
    dataType: 'json',
    data: {
        companyCode : companycode
    },
    success: function(data) {
        console.log('value in data: '+JSON.stringify(data));
        if (data != null) {
            dynamic_tabledetails = data.Table_details;
            table_data = data;
            getTabledetails(dynamic_tabledetails);                  
        } else {
            alert("Error Message");
        }
    },
    error: function(xhr, ajaxOptions, thrownError) {
        console.log("Server is not responding... Please try again: "+thrownError);
    }
});

如果您收到JSON答案,请尝试查找GSON,这可能会对您有所帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM