[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;

 

转载于:https://www.cnblogs.com/pjl1119/p/8610968.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值