json檔案是2.4M的檔案 用mfc決議直接崩掉 我希望打開json檔案 之后在對里面的value (含中文,數字,字母)我希望對中文進行分類 之后再重新寫入json
uj5u.com熱心網友回復:
2.4M不算大...在工程里面加入lib_json.lib(網上找)
然后再專案頭檔案里引入頭檔案
#include <json/value.h>
#include <json/reader.h>
#include <json/writer.h>
然后將json轉成流的方式用json的方式決議出來就OK
簡單例子:
Json::Value jsFoderList;
std::ifstream foderListStream;
foderListStream.open(sFileNamePath.c_str(),0); //打開檔案
Json::Reader jsReaderFlist;
jsReaderFlist.parse(foderListStream,jsFoderList);
uj5u.com熱心網友回復:
// test_json.cpp : 定義控制臺應用程式的入口點。//
#include "stdafx.h"
#include "fstream"
#include "iostream"
#include "string"
#include "assert.h"
#include "json/json.h"
using namespace std;
int main()
{
ifstream fin;
fin.open("hero_info.json");
assert(fin.is_open());
Json::Reader reader;
Json::Value root;
if (!reader.parse(fin, root, false))
{
return -1;
}
std::string name = root["name"].asString();
int age = root["age"].asInt();
std::cout<<name<<std::endl;
std::cout<<age<<std::endl;
cin.get();
return 0;
}
發現每次都是運行到assert就崩了
uj5u.com熱心網友回復:
那是檔案沒正確打開,和json沒關系,把檔案名改成絕對路徑試試。或者看看這個檔案有沒有權限限制了。uj5u.com熱心網友回復:
一直使用JsonCPP很簡單格。
uj5u.com熱心網友回復:
用jsonCPP就可以了,開源的,如4樓說的那樣轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/81014.html
標籤:基礎類
上一篇:怎樣把int型轉為uint型別
下一篇:我不懂錯在哪里了?
