# Include "jsoncpp/include/JSON. H"
// Use the JSON class downloaded from the internet
JSON: Value root;
JSON: Value var;
JSON: Value jfdata;
// For example, a directory level is as follows:
C: // files // testfile // datas // {1. Text, 2. Text, 3. Text. 4. Text}
// The generated directory is as follows:
{"Folders": "Files", "data": [{"Folders": "testfile", "data": [{"Folders": "datas ", "data": [{"FILENAME": "1. text "},{" FILENAME ":" 2. text "},{" FILENAME ":" 3. text "},{" FILENAME ":" 4. text "}]}
Cstringarry folderslist; // assume that all directory structures have been saved.
Folderslist. Add ("Files ");
Folderslist. Add ("ftestfile ");
Folderslist. Add ("datas ");
Cstringarry fileslist; // assume that all directory structures have been saved.
Fileslist. Add ("1. Text ");
Fileslist. Add ("2. Text ");
Fileslist. Add ("3. Text ");
Fileslist. Add ("4. Text ");
// Convert the file into JSON
JSON: Value jldata;
For (INT ifilepos = 0; ifilepos <4, ifilepos ++)
{
JSON: Value piece_ex; // here it store just one piece
// Next 4 lines to apply piece value to JSON struct
Piece_ex ["Folders"] = fileslist. Get (ifilepos );
Jldata. append (piece_ex); // OK, yes we just have apply one piece, then push back to the array
}
// Generate the nested JSON Directory, which is generated from the deepest layer.
JSON: Value jcfdata;
For (INT ifolderspos = 2; ifolderspos> = 0; -- ifolderspos)
{
JSON: Value jccdata;
JSON: Value jccroot;
Jccdata ["fname"] = folderslist. Get (ifolderspos );
If (ifolderspos = listfolders. getcount ()-1)
{
Jccdata ["Folders"] = jldata;
}
Else
{
Jccdata ["Folders"] = jcfdata;
}
Jcfdata = jccdata;
}
Jfdata. append (jcfdata );
VaR ["data"] = jfdata; // Yes, store pieces in Var [value]
Root. append (VAR );
JSON: fastwriter writer;
Cstring szdata (writer. Write (VAR). c_str ());