Jsoncpp資料互動文字格式

2021-08-08 05:25:52 字數 1818 閱讀 3839

json::value  可以表示所有型別

json::reader 將json檔案流或字串解析到json::value,主要呼叫函式parse()

json::writer 將json::value轉化為字串流

若json檔案是utf8格式,因為utf8用bom表明編碼格式,又叫utf-8的簽名,意思是告訴編譯器當前檔案採用何種編碼格式,但是bom會產生輸出,若接受者收到以ef bb bf開頭的位元組流,就是以utf-8格式編碼的,在讀取json檔案時候需要去掉bom

絕對路徑就是檔案的真正存在的路徑,是指從硬碟的根目錄(碟符)開始,進行一級級目錄指向檔案

相對路徑就是以當前檔案為基準進行一級級目錄指向被引用的資源檔案

json檔案:

,

"layout":[,

], "all_reward":

}

/*

* load_json.cpp

* * created on: 2023年9月14日

* author: guojing

*/#include#include#include#include#include #include #include #include #include using namespace std;

const unsigned char *skipbom(const unsigned char *str, int *size)

++i;

++c;

} while (*p != '\0');

*size -= i;

return c;

}int load_json_config(const char *doc,::json::value &conf)

int skip_src_size = statbuf.st_size;

const unsigned char *skip_src = skipbom((const unsigned char *)src, &skip_src_size);//去掉utf8的bom編碼標籤

::json::reader reader;

if(reader.parse((const char*)skip_src,(const char*)(skip_src+skip_src_size),conf)==false)

if (::munmap(src, statbuf.st_size) < 0)

::close(file);

return 0;

}int main()

上面這樣寫會有乙個偶發性讀取不到正確key的bug存在
正確寫法:
const json::value& all_cfg = config_instance->mythical();json::value::members members=all_cfg.getmembernames();

for(json::value::members::iterator ite=members.begin();ite!=members.end();ite++)

直接迭代json檔案中所有鍵值對,通過迭代器.key().ascstring()獲得對應的鍵,iter直接就是json檔案中key所對應的完整的值

void gameconfig::basicconfig::convert_json_to_map(int debug_flag)

}

DOS文字格式轉Unix文字格式Python指令碼

網上一頓查,發現是dos文字格式與unix文字格式有差異的問題。好在ubuntu有dos2unix工具,可以把dos文字格式轉為unix文字格式,使用方法見 但是問題來了,核心原始碼千千萬,不能乙個乙個手動轉吧?所以寫了個python指令碼,這個指令碼的功能是,把當前目錄包括子目錄的所有檔案轉為un...

shell文字格式

linux的shell種類眾多,常見的有 bourne shell usr bin sh或 bin sh bourne again shell bin bash c shell usr bin csh k shell usr bin ksh shell for root sbin sh 等等。不同的...

UGUI 文字格式

先說一種使用 載入text文字的方法 public string loadinfo string path 就是在resources資料夾下,放了乙個儲存為utf 8文字格式,的.txt檔案,然後就可以使用上面方式取到.txt檔案的文字。首行縮排 直接使用網上的取巧辦法,在文字前面加這個東西。jay...