json_spirit provides bool read_string( const String_type& s, Value_type& value )
and bool read( const std::string& s, Value& value )
to read json data from strings.
Here is an example:
string name;
string jsonStr("{\"name\":\"Tom\"}");
json_spirit::Value val;
auto success = json_spirit::read_string(jsonStr, val);
if (success) {
auto jsonObject = val.get_obj();
for (auto entry : jsonObject) {
if (entry.name_ == "name" && entry.value_.type() == json_spirit::Value_type::str_type) {
name = entry.value_.get_str();
break;
}
}
}
You could also use ifstream instead of string to read from json from file.
Please note, according to RFC4627 a string begins and ends with quotation marks.