-
Notifications
You must be signed in to change notification settings - Fork 26
DOCSP-49867: Add JsonReader example #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,23 @@ Extended JSON document into a ``BsonDocument`` object: | |
|
||
{ "_id" : { "$oid" : "573a1391f29313caabcd9637" }, "createdAt" : { "$date" : "1970-01-19T12:51:39.609Z" }, "numViews" : 36520312 } | ||
|
||
Alternatively, you can use the ``JsonReader`` class to read Extended JSON documents. The | ||
following example reads uses the ``JsonReader`` class to read the same Extended JSON document | ||
as the preceding example into a ``BsonDocument`` object: | ||
|
||
.. io-code-block:: | ||
|
||
.. input:: /includes/fundamentals/code-examples/ExtendedJson.cs | ||
:language: csharp | ||
:start-after: start-read-ejson-reader | ||
:end-before: end-read-ejson-reader | ||
:dedent: | ||
|
||
.. output:: | ||
:visible: false | ||
|
||
{ "_id" : { "$oid" : "573a1391f29313caabcd9637" }, "createdAt" : { "$date" : "1970-01-19T12:51:39.609Z" }, "numViews" : 36520312 } | ||
|
||
Write Extended JSON | ||
------------------- | ||
|
||
|
@@ -87,5 +104,4 @@ documentation: | |
- `JsonWriter <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.JsonWriter.html>`__ | ||
- `JsonReader <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.JsonReader.html>`__ | ||
- `JsonWriterSettings <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.JsonWriterSettings.html>`__ | ||
- `JsonReaderSettings <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.JsonReaderSettings.html>`__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Rishit and Boris, this isn't worth discussing. |
||
- `JsonOutputMode <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.IO.JsonOutputMode.html>`__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,19 @@ public static void Main(string[] args) | |
Console.WriteLine(document.ToJson()); | ||
// end-read-ejson | ||
} | ||
|
||
{ | ||
// start-read-ejson-reader | ||
var ejson = "{\n\"_id\": { \"$oid\": \"573a1391f29313caabcd9637\" },\n \"createdAt\": { \"$date\": { \"$numberLong\": \"1601499609\" }},\n\"numViews\": { \"$numberLong\": \"36520312\" }\n}\n\n"; | ||
var subject = new BsonDocumentSerializer(); | ||
mcmorisi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
using (var reader = new JsonReader(ejson)) | ||
{ | ||
var context = BsonDeserializationContext.CreateRoot(reader); | ||
var document = subject.Deserialize<BsonDocument>(context); | ||
Console.WriteLine(document.ToJson()); | ||
} | ||
// end-read-ejson-reader | ||
} | ||
|
||
|
||
{ | ||
// start-write-ejson | ||
|
Uh oh!
There was an error while loading. Please reload this page.