Home > Back-end >  C parsing json file
C parsing json file

Time:09-26

Json file is 2.4 M crash I hope open directly with MFC parsing json file after the value in the (including Chinese, Numbers and letters) I hope again after classifying Chinese to write the json

CodePudding user response:

2.4 M is not big...

In engineering to join lib_json. Lib (online)

Then the project introduced in the header file header files
#include
#include
#include

Then json using json to flow through the way of parsing out on OK
Simple example:
Json: : Value jsFoderList;
STD: : ifstream foderListStream;
FoderListStream. Open (sFileNamePath. C_str (), 0).//open the file
Json: : Reader jsReaderFlist;
JsReaderFlist. Parse (foderListStream jsFoderList);

CodePudding user response:

//test_json. CPP: defines the entry point of the console application,
//

# 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 [r]. "the name" asString ();
Int the age=root [r]. "age" asInt ();

STD: : cout<& lt; Name<& lt; std::endl;
STD: : cout<& lt; Age<& lt; std::endl;
Cin. The get ();
return 0;

}
Find every time is running to assert will collapse

CodePudding user response:

Open that file is not correct, and json it doesn't matter, try change the file name to an absolute path, or check the file permissions,

CodePudding user response:

Always use JsonCPP very simple case,

CodePudding user response:

It is ok to use jsonCPP, open source, such as the 4th floor, put it
  • Related