| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "util/json.h" | |
| 6 | |
| 7 #include "base/json/json_reader.h" | |
| 8 #include "base/logging.h" | |
| 9 | |
| 10 namespace i18n { | |
| 11 namespace addressinput { | |
| 12 | |
| 13 Json::Json() {} | |
| 14 Json::~Json() {} | |
| 15 | |
| 16 bool Json::ParseObject(const std::string& json) { | |
| 17 dict_.reset(); | |
| 18 | |
| 19 // |json| is converted to a |c_str()| here because rapidjson and other parts | |
| 20 // of the standalone library use char* rather than std::string. | |
| 21 scoped_ptr<base::Value> parsed(base::JSONReader::Read(json.c_str())); | |
| 22 if (parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) | |
| 23 dict_.reset(static_cast<base::DictionaryValue*>(parsed.release())); | |
| 24 | |
| 25 return !!dict_; | |
| 26 } | |
| 27 | |
| 28 bool Json::HasStringValueForKey(const std::string& key) const { | |
| 29 base::Value* val = NULL; | |
| 30 dict_->GetWithoutPathExpansion(key, &val); | |
| 31 return val && val->IsType(base::Value::TYPE_STRING); | |
| 32 } | |
| 33 | |
| 34 std::string Json::GetStringValueForKey(const std::string& key) const { | |
| 35 std::string result; | |
| 36 dict_->GetStringWithoutPathExpansion(key, &result); | |
| 37 return result; | |
| 38 } | |
| 39 | |
| 40 } // namespace addressinput | |
| 41 } // namespace i18n | |
| OLD | NEW |