I'm using nodejs + node-tds to connect to a SqlServer 2008r2 express database. I'm retrieving an object with a uniqueidentifier and returning the entire object as json.
I can retrieve the row fine, but when I try to serialize the response to json, it comes out funky:
{
"Id": "�<�E�ԃM��\u0000ؚ��J",
"RealName": "Zachary Yates"
}
Here's the code I'm using:
var q = conn.createStatement("select u.Id, u.RealName from [User] u where u.Id = @id;",
{
id: { type: "uniqueidentifier" }
});
q.on("row", function(row)
{
var user =
{
Id: row.getValue("Id").toString()
, RealName: row.getValue("RealName")
};
res.json(user);
});
q.execute({id: uid});
You've probably got some character-encoding mismatch. Try casting id
to a string in your SQL itself; that should force the right encoding.