diff options
Diffstat (limited to 'cpp/src/util/json.cc')
-rw-r--r-- | cpp/src/util/json.cc | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/cpp/src/util/json.cc b/cpp/src/util/json.cc index d819bb2..352c62b 100644 --- a/cpp/src/util/json.cc +++ b/cpp/src/util/json.cc @@ -139,23 +139,19 @@ const std::vector<std::string>& Json::GetKeys() const { return impl_->GetKeys(); } -bool Json::HasStringValueForKey(const std::string& key) const { - assert(impl_ != NULL); - - // Member is owned by impl_. - const Value::Member* member = impl_->FindMember(key); - return member != NULL && member->value.IsString(); -} - -std::string Json::GetStringValueForKey(const std::string& key) const { +bool Json::GetStringValueForKey(const std::string& key, + std::string* value) const { assert(impl_ != NULL); + assert(value != NULL); // Member is owned by impl_. const Value::Member* member = impl_->FindMember(key.c_str()); - assert(member != NULL); - assert(member->value.IsString()); - return std::string(member->value.GetString(), - member->value.GetStringLength()); + if (member == NULL || !member->value.IsString()) { + return false; + } + + value->assign(member->value.GetString(), member->value.GetStringLength()); + return true; } bool Json::HasDictionaryValueForKey(const std::string& key) const { |