C 中怎樣把JSON檔案快速轉換為物件類

2021-09-29 16:31:43 字數 755 閱讀 4675

首先需要在程式中定義乙個和json格式相同的類

比如如下的jsonconfig 裡面可以定義json物件中的各種屬性

public class jsonconfig

然後我們就可以快速的讀取檔案中的資料

方法一

jsonconfig config = new jsonconfig();

string filepath = string.empty;//檔案的路徑 一遍為json 或者txt檔案

using (system.io.streamreader file = system.io.file.opentext(filepath))

}

方法二:

jsonconfig config = new jsonconfig();

string filepath = string.empty;//檔案的路徑 一遍為json 或者txt檔案

streamreader sr = new streamreader(filepath, encoding.getencoding("gb2312"));

string content = sr.readline();//如果使用這種方法要根據實際情況讀取所有的行

sr.dispose();

config = jsonconvert.deserializeobject(content);

以上是提供的兩種讀取檔案轉換為物件類的方法

怎樣簡單快速的把PDF轉換成word

現在有很多文件資料都是pdf格式,這種文件格式雖然可以編輯,但比較複雜,所以很多人會將pdf文件格式轉成word文件,這樣對文件的內容更加便於利用,而且也便於編輯。但是如果直接通過複製貼上將文件中的內容複製到word中,那麼對頁面的排版會有很大影響,而且不能一次全部複製。那除了複製貼上怎麼可以簡單快...

怎樣把dmp檔案匯入oracle中

怎樣把 dmp檔案匯入 oracle中首先 詢問對方資料 庫的表空 間名稱和大小,然後在你的 oracle 中建立相應表空 間,最後使用 imp命令 匯入資料 imp username password sid file dmp fromuser touser tables 其中,fromuser若...

C 中開啟TXT檔案轉換成JSON檔案

void changetojson while txt end txt end n end txt.size string temp txt.substr pos,end pos info k temp txt txt.substr end if txt 0 n pragma endregion p...