获取错误的原因使用套接字编程解析phonegap中的数据时 [英] Reason for getting Error While parsing the data in phonegap using socket programming

查看:122
本文介绍了获取错误的原因使用套接字编程解析phonegap中的数据时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i我正在进行套接字编程但是在响应中出现错误。

i我正在使用它来做套接字编程

http://anismiles.wordpress.com/2011/02/03/websocket -support-in-android%E2%80%99s-phonegap-apps / [ ^ ]



但是当我调试的时候我的程序我在该方法中获取我的.java文件中的所有数据。

  private  字符串 buildLoadData(字符串 _event,字符串 _data){
字符串 _d = javascript:WebSocket.on + _event + +
{
+ \ _target \:\ + webSocketId + \, +
\_data \:' + data + +
} +
;
Logger.log(_d);
return _d;
}





这是_d打印..



 WebSocket.onmessage({_ target:WEBSOCKET.54,data:'!! 20W)0 
(注:在公开场地!#10W *。) 0
法院:!$ 10W *我是!%10W +开始!&10W +到!\'10W +重新!(10W,服务!)10W,律师!* 10W,' })
---------------------------------



但是从Html我需要数据来显示我调用这个java方法。但我只得到这个结果



 var socket =  new  WebSocket('  ws://192.168 .1.3:8101 /'); 

// 在建立连接后推送消息。
socket.onopen = function(){

socket.send(' Hello World'
};

// 从服务器推送的警报消息
socket.onmessage = function(msg){
// alert(TTTTT+ JSON.stringify(msg));
$( 。test_h)。val(JSON.stringify( MSG))KEYUP();
console.log( TTTTT + JSON.stringify(msg));
};

// 警报关闭事件
socket.onclose = function (){
alert(' closed');
};



在控制台中我得到了这个,....

 06-27 11:04:36.156 :I / Web控制台(924):TTTTT {_ target:WEBSOCKET.54,data:!! 2}在file:///android_asset/www/index.html:52 
然后我得到这样的

06-27 10:53:25.136:D / CordovaLog(871):未捕获的SyntaxError:意外的令牌ILLEGAL
未捕获的SyntaxError:在null时出现意外的令牌ILLEGAL: 1
它会一次又一次地打印出来这条消息
未捕获的SyntaxError:在null时出现意外的令牌ILLEGAL:1
?如何删除此错误。?

解决方案

10W *我是!%10W +去!&10W +到!\'10W +重新!(10W,发售!)10W,律师!* 10W,'})
---------------------------------



但是从Html我需要数据来显示我调用这个java方法。但我只得到这个结果



 var socket =  new  WebSocket('  ws://192.168.1.3:8101 /'); 

// 在建立连接后推送消息。
socket.onopen = function(){

socket.send(' Hello World'
};

// 从服务器推送的警报消息
socket.onmessage = function(msg){
// alert(TTTTT+ JSON.stringify(msg));


。test_h)。 VAL(JSON.stringify(MSG))KEYUP();
console.log( TTTTT + JSON.stringify(msg));
};

// 警报关闭事件
socket.onclose = function (){
alert(' closed');
};



在控制台中我得到了这个,....

 06-27 11:04:36.156 :I / Web控制台(924):TTTTT {_ target:WEBSOCKET.54,data:!! 2}在file:///android_asset/www/index.html:52 
然后我得到这样的

06-27 10:53:25.136:D / CordovaLog(871):未捕获的SyntaxError:意外的令牌ILLEGAL
未捕获的SyntaxError:在null时出现意外的令牌ILLEGAL: 1
它会一次又一次地打印出来这条消息
未捕获的SyntaxError:在null时出现意外的令牌ILLEGAL:1
?如何删除此错误。?


Hi i am doing socket programming But getting error in response .
i am using this like to do socket programming
http://anismiles.wordpress.com/2011/02/03/websocket-support-in-android%E2%80%99s-phonegap-apps/[^]

But when i debug my program i am getting all data in my .java file in that method.

private String buildLoadData(String _event, String _data) {
        String _d =  "javascript:WebSocket.on" + _event + "(" + 
                    "{"
                    + "\"_target\":\"" + webSocketId + "\"," + 
                    "\"_data\":'" + data + "'" + 
                    "}" + 
                ")";
        Logger.log(_d);
        return _d;
    }



Here is _d print ..

WebSocket.onmessage({"_target":"WEBSOCKET.54","data":'!!20W)0
(Note:  In open court at !#10W*.)0
THE COURT:  !$10W*I\'m !%10W+going !&10W+to !\'10W+re!(10W,serve !)10W,counsel !*10W,'})
---------------------------------


But from Html where i need data to show i call this java method.But i am getting only this result

   var socket = new WebSocket('ws://192.168.1.3:8101/');

// push a message after the connection is established.
socket.onopen = function() {

    socket.send('Hello World')
};

// alerts message pushed from server
socket.onmessage = function(msg) {
//alert("TTTTT"+JSON.stringify(msg));
$(".test_h").val(JSON.stringify(msg)).keyup();
    console.log("TTTTT"+JSON.stringify(msg));
};

// alert close event
socket.onclose = function() {
    alert('closed');
}; 


In console i am getting this,....

    06-27 11:04:36.156: I/Web Console(924): TTTTT{"_target":"WEBSOCKET.54","data":"!!2"} at file:///android_asset/www/index.html:52
then after i am getting like this

     06-27 10:53:25.136: D/CordovaLog(871): Uncaught SyntaxError: Unexpected token ILLEGAL
    Uncaught SyntaxError: Unexpected token ILLEGAL at null:1
    it is printed again and again this message
    Uncaught SyntaxError: Unexpected token ILLEGAL at null:1
    ?How to remove this error.?

解决方案

10W*I\'m !%10W+going !&10W+to !\'10W+re!(10W,serve !)10W,counsel !*10W,'}) ---------------------------------


But from Html where i need data to show i call this java method.But i am getting only this result

   var socket = new WebSocket('ws://192.168.1.3:8101/');

// push a message after the connection is established.
socket.onopen = function() {

    socket.send('Hello World')
};

// alerts message pushed from server
socket.onmessage = function(msg) {
//alert("TTTTT"+JSON.stringify(msg));


(".test_h").val(JSON.stringify(msg)).keyup(); console.log("TTTTT"+JSON.stringify(msg)); }; // alert close event socket.onclose = function() { alert('closed'); };


In console i am getting this,....

    06-27 11:04:36.156: I/Web Console(924): TTTTT{"_target":"WEBSOCKET.54","data":"!!2"} at file:///android_asset/www/index.html:52
then after i am getting like this

     06-27 10:53:25.136: D/CordovaLog(871): Uncaught SyntaxError: Unexpected token ILLEGAL
    Uncaught SyntaxError: Unexpected token ILLEGAL at null:1
    it is printed again and again this message
    Uncaught SyntaxError: Unexpected token ILLEGAL at null:1
    ?How to remove this error.?


这篇关于获取错误的原因使用套接字编程解析phonegap中的数据时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆