[英]Why can't assign a string variable to json::value object?
This initialization is possible and can make the json::value object with the value of "hello1" as follows. 这种初始化是可能的,并且可以使json :: value对象的值为“ hello1”,如下所示。
json::value v1 = json::value::string(U("hello1")); // ok
But this initialization is not working. 但是这种初始化不起作用。 What is the reason for that?
是什么原因呢? How to create a JSON object by using the value of a variable such as string or char*.
如何通过使用诸如string或char *之类的变量的值创建JSON对象。
string str1 = "Hello2";
json::value v2 = json::value::string(str1); //Error (1)
json::value v3 = json::value::string(U(str1)); //Error (2)
Error 1 错误1
Severity Code Description Project File Line Suppression State
Error C2248 'web::json::value::string': cannot access private member declared in class 'web::json::value' StolenDetailsService c:\users\nuwanst\source\repos\stolendetailsservice\stolendetailsservice\dbhandler.cpp 62
Error 2 错误2
Severity Code Description Project File Line Suppression State
Error C2065 'Lstr1': undeclared identifier StolenDetailsService c:\users\nuwanst\source\repos\stolendetailsservice\stolendetailsservice\dbhandler.cpp 62
I used streams. 我用流。 It works for me.
这个对我有用。
string st1="Hello";
utility::stringstream_t ss1;
ss1 << str1;
json::value Jobj = json::value::parse(ss1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.