如何在c++中存储一个字符串集合作为键,json作为值
how to store a collection of string as key and json as value in c++
我正试图将键值对的集合存储在cpp中,其中key
将是一个字符串,值也是如此——在我的情况下,是一个表示对象的JSON字符串。
然后我需要使用Key1访问这个json对象例如
Key1=name1
值1={name:"Anil Gautam","age":25}
Key2=name2
值2=**strong text** = {name:"Sharan Gupta","age":26}
我想访问
{name:"Anil Gautam","age":25}
当我输入"name1"时。我可以做些什么来将这种数据存储在cpp中。
看起来应该将Value数据放入一个结构中:
struct Value
{
std::string name;
unsigned int age;
};
现在有一个使用字符串和值结构的std::map
:
typedef std::map<std::string, Value> Map_Type;
插入类似于:
Value v("Anil Gautam", 25);
Map_Type entries;
entries["name1"] = v;
获取值:
Value v2;
v2 = entries["name1"];
相关文章:
- 显示字符串的集合和子集
- 如何在集合中的特定字符串中查找子字符串
- 在 c++ 中将集合转换为向量和向量转换为字符串时出现运行时异常
- 将字符串集合中的元素添加到字符串集合的向量中
- 将字符串保存在集合中时,C_STR()仍然有效
- 如何使用for_each,transform,Iterator和lambda的某种组合将STD ::集合的字符串转换为小
- 集合中元素的子字符串
- variadic宏可从未知参数集合中生成字符串向量
- 使用shared_ptr<字符串>转换为一个无序集合<字符串>
- 限制集合中的字符串长度
- 在c++中的graphics.h上打印包含字符串的集合
- remove_if字符串匹配集合中的给定字符串
- 创建字符串 c++ 的常量集集合
- 为什么这段代码找不到我集合中最长字符串的长度?
- 访问集合c++中字符串的第一个字母
- 具有前缀和后缀查询的字符串集合的数据结构
- 如何在<string>没有 std::string 中介的情况下制作一个支持通过 C 字符串查找的集合?
- 生成与集合中的字符串不匹配的字符串
- 具有字符串成员的结构的集合与向量
- 如何在c++中存储一个字符串集合作为键,json作为值