您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx使用Jsoncpp在android运行的问题

2013-04-19 12:39 399 查看
本来是使用ifsteam直接读的文件,发现android不支持,后来网上搜了下发现cocos2dx自身就带有读取文件的api

我实在是太水了

#include "JsonUtils.h"
#include "cocos2d.h"
#include <fstream>
using namespace cocos2d;

Json::Value JsonUtils::getJsonFromFile(const char* fileName){
    Json::Reader reader;
    const char* pszFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(fileName);
    
    unsigned long size;
    char *pFileContent = (char*)CCFileUtils::sharedFileUtils()->getFileData(pszFullPath, "rb", &size);
    std::string jsonfile ;
    jsonfile.assign(pFileContent, size);
    
    
    CCAssert( size > 0, "file is open fail!");
    Json::Value root;
    if  (!reader.parse(jsonfile, root, false )) {
        CCAssert(false, "Json::Reader Parse error!");
    }
    return root;
}


贴个示例,也不知道jsoncpp怎么读char*,转成string给jsoncpp读了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐