【发布时间】:2014-03-19 13:06:19
【问题描述】:
我正在从 MongoDB 检索数据,然后将其发送到客户端:
var bsonDocument = ... retrieve from database ...
var dto = new Dto { MyBson = bsonDocument.ToJson() };
在客户端上,我尝试使用 JSON.parse 解析 MyBson 属性。
我收到以下错误:SyntaxError: Unexpected token N。我猜这是因为其中一个属性看起来像这样:
{ ..., "SomeIntProp" : NumberLong(70) }
JavaScript 解析器根本不理解 Bson 数据类型:NumberLong。
我应该如何将 BsonDocument 转换为 JSON,以便输出省略 NumberLong?
【问题讨论】:
-
这里是一个链接,它显示了它是如何在 php 中完成的:github.com/bobthecow/genghis/blob/master/src/php/Genghis/…。我在 JS 中做了同样的事情。
标签: javascript .net json mongodb bson