0

This initialization is possible and can make the json::value object with the value of "hello1" as follows.

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 str1 = "Hello2";
    json::value v2 = json::value::string(str1);   //Error (1)
    json::value v3 = json::value::string(U(str1)); //Error (2)

Error 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

Severity    Code    Description Project File    Line    Suppression State
Error   C2065   'Lstr1': undeclared identifier  StolenDetailsService    c:\users\nuwanst\source\repos\stolendetailsservice\stolendetailsservice\dbhandler.cpp   62  
Nwn
  • 561
  • 2
  • 9
  • 33
  • 1
    I think you have swapped the errors: `U()` looks like a macro which pastes a `L` onto its argument, which only works with string literals but will only make up the name of a non-existing `Lstr1` variable here. – Quentin Oct 21 '17 at 08:27
  • yeah , thanks i fixed it. please tell me if u know is there anyother way to construct a json object with a string variable – Nwn Oct 21 '17 at 08:32

1 Answers1

1

I used streams. It works for me.

   string st1="Hello";
    utility::stringstream_t ss1;
    ss1 << str1;
    json::value Jobj = json::value::parse(ss1);
Nwn
  • 561
  • 2
  • 9
  • 33