为什么我在真正的Android设备和chrome上收到不同的错误

时间:2012-09-22 18:15:28

标签: json jquery jquery-mobile

我在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));
            }
    });             
}

1 个答案:

答案 0 :(得分:1)

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

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

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