zoukankan      html  css  js  c++  java
  • [IOS微信] PList文件解析,boost数据读取

    最近在解析IOS版微信数据中的 mmsetting.archive 文件时,第一次接触到PList文件。

    注:mmsetting.archive  不是一个标准的PList文件,其中含有汉字,并且很多value没有对应的key值

    在GITHUB上找到了开源的PListCpp库,可以解析PList文件。经过我的修改完善,可以读取汉字(见上一篇博客)

    但读取出的数据在一个列表中,用到boost::any,

    我对boost并不熟悉,经大牛帮忙,读取的数据方式如下:

     1      std::map<std::string, boost::any> dict;
     2         Plist::readPlist(“mmsetting.archive”, dict); 
     3 
     4         for (auto it = dict.begin(); it != dict.end(); ++it)
     5         {
     6 //             if (it->first == "$version")
     7 //             {
     8 //                 const int& ver = boost::any_cast<const int&>(it->second);
     9 // 
    10 //                 cout << "$version: " << ver << endl;
    11 //             }
    12             std::string strStringType = "class std::basic_string";
    13             std::string strMapType = "class std::map";
    14 
    15             if (it->first == "$objects")
    16             {
    17                 const std::vector<boost::any>& plistArray = boost::any_cast<const std::vector<boost::any>&>(it->second);
    18                 for (int i = 0; i < plistArray.size(); i++)
    19                 {
    20                     // plistArray[i].type()
    21                     std::string typeName = plistArray[i].type().name();
    22                     std::string key_context_type = typeName.substr(0, strStringType.length());
    23 
    24                     if (strStringType == key_context_type)
    25                     {
    26                         const std::string & key_context = boost::any_cast<const std::string &> (plistArray[i]);
    27                         //cout << key_context_type.c_str() << ": " << key_context.c_str() << endl;
    28                         vec.emplace_back(key_context);
    29                     }
    30                     else
    31                     {
    32                         key_context_type = typeName.substr(0, strMapType.length());
    33                         if (strMapType == key_context_type)
    34                         {
    35                             //cout << key_context_type.c_str() << endl;
    36                             //const map<string, boost::any>& subdict = boost::any_cast<const map<string, boost::any> &> (plistArray[i]);
    37                         }
    38                     }
    39 
    40                 }
    41             }
    42         }
    43 
    44 
    45         //         const vector<boost::any>& plistArray = boost::any_cast<const vector<boost::any>&>(dict.find("testArray")->second);
    46         //         cout << boost::any_cast<const int64_t&>(plistArray[0]) << endl;
    47         //         cout << boost::any_cast<const string&>(plistArray[1]).c_str() << endl;
  • 相关阅读:
    获取动态类型变量的属性值
    C#项目实例中读取并修改App.config文件
    c#防止多次运行代码收集
    c# winform 关闭窗体时同时结束线程实现思路
    C# App.config 自定义 配置节 报错“配置系统未能初始化” 解决方法
    在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke 解决办法
    用 C# 在 Windows 7 中写注册表想到的
    this指针
    UML类图,用例图,时序图
    常见的框架模式:MVC MVP MTV等
  • 原文地址:https://www.cnblogs.com/pjl1119/p/8610968.html
Copyright © 2011-2022 走看看