@@ -391,6 +391,14 @@ namespace json
391
391
// / <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
392
392
_ASYNCRTIMP static value parse (const utility::string_t &);
393
393
394
+ // / <summary>
395
+ // / Attempts to parse a string and construct a JSON value.
396
+ // / </summary>
397
+ // / <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
398
+ // / <param name="errorCode">If parsing fails, the error code is greater than 0</param>
399
+ // / <returns>The parsed object. Returns web::json::value::null if failed</returns>
400
+ _ASYNCRTIMP static value parse (const utility::string_t &, std::error_code&);
401
+
394
402
// / <summary>
395
403
// / Serializes the current JSON value to a C++ string.
396
404
// / </summary>
@@ -411,6 +419,14 @@ namespace json
411
419
// / <returns>The JSON value object created from the input stream.</returns>
412
420
_ASYNCRTIMP static value parse (utility::istream_t &input);
413
421
422
+ // / <summary>
423
+ // / Parses a JSON value from the contents of an input stream using the native platform character width.
424
+ // / </summary>
425
+ // / <param name="input">The stream to read the JSON value from</param>
426
+ // / <param name="errorCode">If parsing fails, the error code is greater than 0</param>
427
+ // / <returns>The parsed object. Returns web::json::value::null if failed</returns>
428
+ _ASYNCRTIMP static value parse (utility::istream_t &input, std::error_code& error);
429
+
414
430
// / <summary>
415
431
// / Writes the current JSON value to a stream with the native platform character width.
416
432
// / </summary>
@@ -424,6 +440,14 @@ namespace json
424
440
// / <param name="stream">The stream to read the JSON value from</param>
425
441
_ASYNCRTIMP static value parse (std::istream& stream);
426
442
443
+ // / <summary>
444
+ // / Parses a JSON value from the contents of a single-byte (UTF8) stream.
445
+ // / </summary>
446
+ // / <param name="stream">The stream to read the JSON value from</param>
447
+ // / <param name="errorCode">If parsing fails, the error code is greater than 0</param>
448
+ // / <returns>The parsed object. Returns web::json::value::null if failed</returns>
449
+ _ASYNCRTIMP static value parse (std::istream& stream, std::error_code& error);
450
+
427
451
// / <summary>
428
452
// / Serializes the content of the value into a single-byte (UTF8) stream.
429
453
// / </summary>
@@ -634,6 +658,70 @@ namespace json
634
658
~json_exception () CPPREST_NOEXCEPT {}
635
659
};
636
660
661
+ namespace details
662
+ {
663
+ enum json_error
664
+ {
665
+ left_over_character_in_stream = 1 ,
666
+ malformed_array_literal,
667
+ malformed_comment,
668
+ malformed_literal,
669
+ malformed_object_literal,
670
+ malformed_numeric_literal,
671
+ malformed_string_literal,
672
+ malformed_token,
673
+ mismatched_brances,
674
+ nesting,
675
+ unexpected_token
676
+ };
677
+
678
+ class json_error_category_impl : public std ::error_category
679
+ {
680
+ public:
681
+ virtual const char * json_error_category_impl::name () const
682
+ {
683
+ return " json" ;
684
+ }
685
+
686
+ virtual std::string json_error_category_impl::message (int ev) const
687
+ {
688
+ switch (ev)
689
+ {
690
+ case json_error::left_over_character_in_stream:
691
+ return " Left-over characters in stream after parsing a JSON value" ;
692
+ case json_error::malformed_array_literal:
693
+ return " Malformed array literal" ;
694
+ case json_error::malformed_comment:
695
+ return " Malformed comment" ;
696
+ case json_error::malformed_literal:
697
+ return " Malformed literal" ;
698
+ case json_error::malformed_object_literal:
699
+ return " Malformed object literal" ;
700
+ case json_error::malformed_numeric_literal:
701
+ return " Malformed numeric literal" ;
702
+ case json_error::malformed_string_literal:
703
+ return " Malformed string literal" ;
704
+ case json_error::malformed_token:
705
+ return " Malformed token" ;
706
+ case json_error::mismatched_brances:
707
+ return " Mismatched braces" ;
708
+ case json_error::nesting:
709
+ return " Nesting too deep" ;
710
+ case json_error::unexpected_token:
711
+ return " Unexpected token" ;
712
+ default :
713
+ return " Unknown json error" ;
714
+ }
715
+ }
716
+ };
717
+
718
+ inline const json_error_category_impl& json_error_category ()
719
+ {
720
+ static json_error_category_impl instance;
721
+ return instance;
722
+ }
723
+ }
724
+
637
725
// / <summary>
638
726
// / A JSON array represented as a C++ class.
639
727
// / </summary>
0 commit comments