exception while parsing a string

Jan 23, 2014 at 5:12 AM
I am trying to parse a string but always end up with a `not a string` exception. 

utility::string_t data = dataTextBox->Text->Data();
                        OutputDebugString(data.c_str());//output is::{"name":"new fold"}
                        web::json::value jsonData = web::json::value::parse(data);
                    catch (std::exception& exc){
                        OutputDebugString(utility::conversions::to_string_t( exc.what()).c_str());
Jan 23, 2014 at 5:20 AM
Edited Jan 23, 2014 at 5:20 AM
my bad..the exception was being thrown by the second OutputDebugString.
Jan 23, 2014 at 4:46 PM

Yes what you are seeing is the fact that json::value::as_string() only works if the actual underlying json value is indeed a string. All the as_* methods act as a bridge to the C++ type system. Think about that method as asking for the json value as a C++ string as opposed to serialization. For example json::value::as_integer only works if the underlying json value is a integer number value. The json::value::to_string() method really is serialization, it looks like that is what you mean to use here. json::value::to_string() synonymous as using json::value::serialize. You can test to see each json value is by using the is_array(), is_number(), is_sting(), etc... methods, or with the json::value::type() method.

Hope that clarifies,