64,680
社区成员
发帖
与我相关
我的任务
分享
#include "jsonfactory.h"
#include <fstream>
#include <assert.h>
// 解析json 文件的master 方法
bool JSONFactory::jsonFileFactory(string filename){
success = false;
// file read:
ifstream fin(filename);
if (fin) {
// 首先定位到结尾,了解文件大小
fin.seekg (0, fin.end);
int length = fin.tellg();
// 再重新定位到头,进行操作
fin.seekg (0, fin.beg);
char * buffer = new char [length-1];
std::cout << "Reading " << length << " characters... "<<endl;
fin.read (buffer,length);
int end = ((string)buffer).find_last_of("}");
string temp = ((string)buffer).substr(0,end+1);
cout<<"temp----"<<temp<<endl;
Reader reader; //json解析
Value root; //表示一个json格式的对象
if(reader.parse(temp, root,true)){ // 解析出错,怎么回事????????????
cout<<"im parsing...."<<endl;
parseObj(root);
success = true;
return success;
}
}
return success;
}