Skip to content

[question] how to get a string value by pointer #683

Description

@zhishupp

I wrapped a C lib for using json.hpp, like this:

json_string = {"file":"/opt/test.conf"}

set json_string to a static json object

static json para = json::parse(json_string);

`
extern "C" const char*

get_json_string()

{

if (para["file"].is_string())     
            
{                        

    return para["file"].get<std::string>().c_str();      
           
}          

}
`

but actually, get_json_string cannot get the real address of para, so how to get a string value in this way ?

I don't want to use strcpy like this:
`
get_json_string(char* value)

{

if (para["file"].is_string())

{

    strcpy(value, para["file"].get<std::string>().c_str());

}

}
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions