@@ -171,21 +171,6 @@ namespace web { namespace json
171171 // / <returns>The JSON value object that contains the result of the assignment.</returns>
172172 _ASYNCRTIMP value &operator =(value &&);
173173
174- // / <summary>
175- // / Constructor creating a JSON value from an input stream, by parsing its contents.
176- // / </summary>
177- // / <param name="input">The stream to read the JSON value from</param>
178- // / <returns>The JSON value object created from the input stream.</returns>
179- _ASYNCRTIMP static value parse (utility::istream_t &input);
180-
181- #ifdef _MS_WINDOWS
182- // / <summary>
183- // / Constructor creating a JSON value from a byte buffer stream, by parsing its contents.
184- // / </summary>
185- // / <param name="stream">The stream to read the JSON value from</param>
186- _ASYNCRTIMP static value parse (std::istream& stream);
187- #endif
188-
189174 // Static factories
190175
191176 // / <summary>
@@ -312,31 +297,44 @@ namespace web { namespace json
312297 // / <returns>The number of children. 0 for all non-composites.</returns>
313298 size_t size () const ;
314299
300+ // / <summary>
301+ // / Parse a string and construct a JSON value.
302+ // / </summary>
303+ // / <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
304+ _ASYNCRTIMP static value parse (utility::string_t );
305+
315306 // / <summary>
316307 // / Serialize the current JSON value to a C++ string.
317308 // / </summary>
318309 // / <returns>A string representation of the value</returns>
319310 _ASYNCRTIMP utility::string_t to_string () const ;
320311
321312 // / <summary>
322- // / Parse a string and construct a JSON value .
313+ // / Parse a JSON value from the contents of an input stream using the native platform character width .
323314 // / </summary>
324- // / <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
325- _ASYNCRTIMP static value parse (utility::string_t );
315+ // / <param name="input">The stream to read the JSON value from</param>
316+ // / <returns>The JSON value object created from the input stream.</returns>
317+ _ASYNCRTIMP static value parse (utility::istream_t &input);
326318
327- #ifdef _MS_WINDOWS
328319 // / <summary>
329- // / Write the current JSON value as a double-byte string to a stream instance .
320+ // / Write the current JSON value to a stream with the native platform character width .
330321 // / </summary>
331322 // / <param name="stream">The stream that the JSON string representation should be written to.</param>
332- _ASYNCRTIMP void serialize (std::basic_ostream<utf16char> &stream) const ;
333- #endif
323+ _ASYNCRTIMP void serialize (utility::ostream_t &stream) const ;
334324
325+ #ifdef _MS_WINDOWS
335326 // / <summary>
336- // / Serialize the content of the value into a stream in UTF8 format
327+ // / Parse a JSON value from the contents of a single-byte (UTF8) stream.
328+ // / </summary>
329+ // / <param name="stream">The stream to read the JSON value from</param>
330+ _ASYNCRTIMP static value parse (std::istream& stream);
331+
332+ // / <summary>
333+ // / Serialize the content of the value into a single-byte (UTF8) stream.
337334 // / </summary>
338335 // / <param name="stream">The stream that the JSON string representation should be written to.</param>
339- _ASYNCRTIMP void serialize (std::basic_ostream<char >& stream) const ;
336+ _ASYNCRTIMP void serialize (std::ostream& stream) const ;
337+ #endif
340338
341339 // / <summary>
342340 // / Convert the JSON value to a C++ double, if and only if it is a number value.
@@ -381,6 +379,13 @@ namespace web { namespace json
381379 return !((*this ) == other);
382380 }
383381
382+ // / <summary>
383+ // / Access a field of a JSON object.
384+ // / </summary>
385+ // / <param name="key">The name of the field</param>
386+ // / <returns>The value kept in the field; null if the field does not exist</returns>
387+ value get (const utility::string_t &key) const ;
388+
384389 // / <summary>
385390 // / Access a field of a JSON object.
386391 // / </summary>
@@ -406,6 +411,13 @@ namespace web { namespace json
406411public:
407412#endif
408413
414+ // / <summary>
415+ // / Access an element of a JSON array.
416+ // / </summary>
417+ // / <param name="key">The index of an element in the JSON array</param>
418+ // / <returns>The value kept at the array index; null if outside the boundaries of the array</returns>
419+ value get (size_t index) const ;
420+
409421 // / <summary>
410422 // / Accesses an element of a JSON array.
411423 // / </summary>
@@ -530,6 +542,9 @@ namespace web { namespace json
530542 virtual const json::value::element_vector &elements () const { throw json_exception (U (" not an array" )); }
531543 virtual const json::value::field_map &fields () const { throw json_exception (U (" not an object" )); }
532544
545+ virtual value get_field (const utility::string_t &) const { throw json_exception (U (" not an object" )); }
546+ virtual value get_element (std::vector<value>::size_type) const { throw json_exception (U (" not an array" )); }
547+
533548 virtual value &index (const utility::string_t &) { throw json_exception (U (" not an object" )); }
534549 virtual value &index (std::vector<value>::size_type) { throw json_exception (U (" not an array" )); }
535550
@@ -775,6 +790,7 @@ namespace web { namespace json
775790
776791 virtual json::value::value_type type () const { return json::value::Object; }
777792
793+ _ASYNCRTIMP virtual value get_field (const utility::string_t &) const ;
778794 _ASYNCRTIMP virtual json::value &index (const utility::string_t &key);
779795 _ASYNCRTIMP virtual const json::value &cnst_index (const utility::string_t &key) const ;
780796
@@ -843,6 +859,18 @@ namespace web { namespace json
843859
844860 virtual json::value::value_type type () const { return json::value::Array; }
845861
862+ virtual value get_element (std::vector<value>::size_type index) const
863+ {
864+ #ifdef _MS_WINDOWS
865+ msl::utilities::SafeInt<std::vector<json::value>::size_type> idx (index);
866+ msl::utilities::SafeInt<std::vector<json::value>::size_type> size (m_elements.size ());
867+ #else
868+ size_t idx = index;
869+ size_t size = m_elements.size ();
870+ #endif
871+ return (idx >= size) ? value () : m_elements[index].second ;
872+ }
873+
846874 virtual json::value &index (std::vector<json::value>::size_type index)
847875 {
848876#ifdef _MS_WINDOWS
@@ -925,6 +953,17 @@ namespace web { namespace json
925953 return m_value->size ();
926954 }
927955
956+ inline json::value json::value::get (const utility::string_t & key) const
957+ {
958+ return m_value->get_field (key);
959+ }
960+
961+ inline json::value json::value::get (size_t index) const
962+ {
963+ return m_value->get_element (index);
964+ }
965+
966+
928967 inline json::value::iterator json::value::begin ()
929968 {
930969 return m_value->elements ().begin ();
0 commit comments