如何将消息转换为json对象

时间:2014-05-30 12:32:34

标签: json node.js

我正在使用一个名为fire packets的客户端程序将一些十六进制数据发送到服务器程序,其中服务器在指定端口上侦听。服务器程序运行良好,它接收来自客户端的消息,但需要将消息转换为json对象,其中结果未定义,尝试时可以任何人请告诉我如何将消息转换为json对象。将附加下面的服务器程序,

var dgram = require('dgram');
var server = dgram.createSocket("udp4");
var fs = require('fs');
server.on("error", function(err) {
    console.log("Error:" + err.stack);
    server.close();
});
server.on("message", function(msg, rinfo) {
    console.log("server got the message :" + msg + "from" + rinfo.address + "from the port" + rinfo.port);
    fs.writeFile("packet.txt", msg.toString(), 'utf-8', function(err) {
        //var jsonmess=JSON.parse(msg);
        //console.log(jsonmess);
        console.log("written on packet");
    });
});
server.on("listening", function() {
    var address = server.address();
    console.log("Server listening on:" + address.address + "on the port:" + address.port);
});
server.bind(5432);

我通过客户端发送的消息是 4500005100060000801116FB75610CFACF47D1F8501E5014003DD5C383051632426347010101020AC252F131AB52F131AB0776956F2CC65619000002CC0000000000000800005FFF970F07660001080100000032C8  当我对JSON对象进行字符串化时,数据显示为

[131,5,22,50,66,99,71,1,1,1,2,10,194,82,241,49,171,82,241,49,171,7,118,149,111,44,198,86,25,0,0,2,204, 0,0,0,0,0,0,8,0,0,95,255,151,15,7,102,0,1,8,1,0,0,0,50,200]

如何获取通过服务器json对象

上的客户端发送的确切值

0 个答案:

没有答案