0

我在 phonegap 中开发了一个移动应用程序。当我在 Chrome 上测试它时,我没有收到任何错误,并且如果正确填写了数据库。当我通过 eclipse 在真实设备上尝试它时,我收到以下错误。为什么我会收到这些错误?

09-22 19:56:49.568: E/Web Console(6912): Uncaught SyntaxError: Unexpected token } at file:///android_asset/www/index.html#page2:1

09-22 19:56:49.558: E/Web Console(6912): Uncaught SyntaxError: Unexpected token ILLEGAL at file:///android_asset/www/index.html#page2:1

以及在哪里可以找到 } 因为在 index.html 中没有这样的字符。

我在尝试读取一些 JSON 时收到这些错误。

PS我用这段代码来读取一些json

    function billpaymentstxt()
{
var billpaymentsjson = '{"posts" : [', 
    i, 
    line = 0,
    billpayments = 0,
    mybillpaymentsjson,
    Amountint,
    Amountdec;

    jQuery.ajaxSetup({
            'beforeSend' : function(xhr) {
                 xhr.overrideMimeType('text/plain; charset=iso-8859-7');
            },
    });


    jQuery.get('BillPayments.txt',function(data){
//  alert(data.length);
    line=0;

        for (i = 1; i <= ((data.length)/20); i += 1) {
            billpaymentsjson += '{"Id" :' + '"' + data.substr((line+0), 10).trim() + '"'  + ',';
            Amountint = data.substr((line+10), 7).trim();
            Amountdec = data.substr((line+17), 2).trim();
            billpaymentsjson += '"PreviousPayments" : ' + '"'  + Amountint + '.' + Amountdec + '"'  +  '}';
            line = i * 20;
    //alert(line);
            if (line == data.length)
            {
                billpaymentsjson += ']';
            }
            else 
            {
                billpaymentsjson += ',';
            }
        }

        if (line == 0)
        {
            billpaymentjson += ']';
        }


        billpaymentsjson += "}";
        //alert(billpaymentsjson);
            mybillpaymentsjson = jQuery.parseJSON( billpaymentsjson );

            if (((mybillpaymentsjson.posts.length)) == 0) {
                $('#mycontent article').html('<strong>bill - <font color=blue>OK</font></strong>');
            }


            for (i = 0; i < (mybillpaymentsjson.posts.length); i += 1) {

                notesdb.transaction((function(i) {
                    return function(t){       

                        t.executeSql('INSERT into billpayments (barcode, amount, receiptno) VALUES (?,?,?);',
                            [mybillpaymentsjson.posts[i].Id, mybillpaymentsjson.posts[i].PreviousPayments, 0],
                            function(){ 
                                billpayments = billpayments + 1;
                                $('#mycontent article2').html(billpayments + '/' + mybillpaymentsjson.posts.length + ' <strong>billpayments</strong>');

                                if ((mybillpaymentsjson.posts.length) - billpayments == 0) {
                                    $('#mycontent article2').html('<strong>billpayments - <font color=blue>OK</font></strong>');
                                } 
                            }
                        );
                    };
                })(i));
            }
    });             
}
4

1 回答 1

1

据我所知,JSON 无法处理 ISO-8859-7。

http://www.php.net/manual/en/function.json-encode.php

“此功能仅适用于 UTF-8 编码数据。” 也许你可以尝试一些转换

于 2012-10-12T15:55:07.267 回答