plist是以xml文件形式mongodb 存储xml文件的吗

蚂蚁雄心 的BLOG
用户名:蚂蚁雄心
文章数:115
访问量:13543
注册日期:
阅读量:5863
阅读量:12276
阅读量:382050
阅读量:1073884
51CTO推荐博文
一、.json加载,对于下列形式&&[["key","value"],["hot_update_version",0],["totallv",120],["releaseversion",1.5]]一般通过std::string data =&FileUtils::getInstance()-&getStringFromFile(filename); &通过文本rapidjson::D &doc.Parse&rapidjson::kParseDefaultFlags&(data.c_str()); 解析data。解析之后doc应该是一个数组形式的,而且是一个二维数组(或者说是一个矩阵形式)。如果解析没有错误,可以通过doc.size()取得总行数,然后通过rapidjson::Value &v=doc[i]取得每一列的值,它也是一个数组,v.size()取得总列数,通过const auto& value = v[index];取得具体的值,这个值可能是NULL,可能是int,可能是string,可以通过value.IsNull()、value.IsString()、value.IsInt()判断并通过value.GetString()或value.GetInt()等获取该值。对于下列形式"snow" : [& & & [ 2, 3, 7 ],& & & [ 2, 3, 8 ],& & & [ 3, 7, 7 ]& &],& &"cirrus" : [& & & [ 4, 4 ]& &],& &"down" : [ 1, 2, 4, 5, 6 ],& &"target" : [& &[2, 1, 3]& && &],& && "targetScore" : 1000,& "moves" : 15一般通过//获取行数&static const string tileKey = "snow";& auto rowLen = DICTOOL-&getArrayCount_json(json, tileKey.c_str());for (int row = 0; row & rowL ++row){& & & & & &//获取行的值& & & & & & const auto& rowValue = DICTOOL-&getDictionaryFromArray_json(json, tileKey.c_str(), row);& & & & & &//遍历行的值& & & & & & for (rapidjson::SizeType col = 0; col & rowValue.Size(); ++col ){&&&&&&&&&&&&//取得具体值& & & & & & & & if ( rowValue[col].GetInt() ){& & & & & & & & }else{& & & & & & & & }& & & & & & }& & & & }&const auto& moves = DICTOOL-&getIntValue_json(json, "moves", 0);& _moveCounting &=.json文件的生成,通过定义Json::Value root,Json::Value&item,item.append(1),item.append(2),root["test"].append(item),最终通过& & &// 缩进输出Json::StyledW// 输出到文件os.open(sLevelPath);os && sw.write(root);os.close();二、.plist加载,一般通过ValueMap dict = FileUtils::getInstance()-&getValueMapFromFile(filename);获取最外层的ValueMap,该valuemap里面可以嵌套其他valuemap,获取内部嵌套的其他valuemap,可以这样获取,auto dataIter =&dict.find("data"),(此时dataIter相当于一个Value),通过判断if(dataIter != dict.cend()&&dataIter-&second.getType()==Value::Type::MAP){const auto& data = dataIter-&second.asValueMap();}.plist生成,一般通过/*&* Use tinyxml2 to write plist files&*/bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath)三、.xml加载,函数static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLElement** rootNode, tinyxml2::XMLDocument **doc)tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();*doc = xmlD& & & & std::string xmlBuffer = FileUtils::getInstance()-&getStringFromFile(UserDefault::getInstance()-&getXMLFilePath());if (xmlBuffer.empty()){CCLOG("can not read xml file");}xmlDoc-&Parse(xmlBuffer.c_str(), xmlBuffer.size());// get root node*rootNode = xmlDoc-&RootElement();if (nullptr == *rootNode){CCLOG("read root node error");}// find the nodecurNode = (*rootNode)-&FirstChildElement();while (nullptr != curNode){const char* nodeName = curNode-&Value();if (!strcmp(nodeName, pKey)){}curNode = curNode-&NextSiblingElement();}if (curNode&){& & & & if (curNode&-&FirstChild())& & & & {& & & & & & curNode-&FirstChild()-&SetValue(pValue);& & & & }& & & & else& & & & {& & & & & & tinyxml2::XMLText* content = doc-&NewText(pValue);& & & & & & curNode-&LinkEndChild(content);& & & & }}else{if (rootNode){tinyxml2::XMLElement* tmpNode = doc-&NewElement(pKey);//new tinyxml2::XMLElement(pKey);rootNode-&LinkEndChild(tmpNode);tinyxml2::XMLText* content = doc-&NewText(pValue);//new tinyxml2::XMLText(pValue);tmpNode-&LinkEndChild(content);}}& & //.xml生成& & // save file and free docif (doc){doc-&SaveFile(UserDefault::getInstance()-&getXMLFilePath().c_str());}本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:未分类┆阅读(0)┆评论(0)iOS 数据存储(6)
XML属性列表(plist)归档
所谓归档,是一个过程,即用某种格式来保存一个或者多个对象,以便以后还原这些对象。
属性列表是一种XML格式的文件,拓展名为plist。如果对象是NSString、NSDictionary、NSArray、NSData、NSNumber等类型,就可以使用writeToFile:atomically:方法直接将对象写到属性列表文件中,plist也只能存储对象数据类型。
- (NSString *)getFilePath
NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [doc stringByAppendingPathComponent:@"date.plist"];
return fileP
- (IBAction)write:(id)sender
NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[@"Steven", @10, @"Computer Science"] forKeys:@[@"name", @"age", @"major"]];
[dict writeToFile:[self getFilePath] atomically:YES];
- (IBAction)read:(id)sender
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[self getFilePath]];
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSLog(@"%@-%@", key, obj);
三、查看plist文件
用Xcode打开:
用文档编辑器打开:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:16823次
排名:千里之外
原创:86篇
(1)(4)(34)(35)(12)博客访问: 1371716
博文数量: 236
博客积分: 9346
博客等级: 中将
技术积分: 3435
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
在网上找到一个好东西,基于 Perl 的 plutil.pl
文件:plutil.pl.tar.bz2
阅读(6738) | 评论(0) | 转发(1) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。PHP解析XML格式的Plist文件_php吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:123,230贴子:
PHP解析XML格式的Plist文件收藏
演示+源码下载:php_parse_plist.php下载在苹果IOS开发过程中,经常会用到plist格式的文件,它是一种XML格式文件,本文主要基于xml原理来解析plist文件.建立XML解析器和定义元素处理器和字符数据处理器.转自:
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或

我要回帖

更多关于 seafile 文件存储形式 的文章

 

随机推荐