I have a text file that I'm trying to convert to a JSON object using jsoncpp in my c++ application.
The contents of the file is formatted as so:
system type : Atheros AR7241 rev 1
machine : Ubiquiti UniFi
processor : 0
cpu model : MIPS 24Kc V7.4
BogoMIPS : 259.27
Which seems pretty handy to start. I needed to keys to match the first column and the values the second column, as so:
{ "meh" : [{ "system type" : "Atheros AR7241 rev 1", "machine" : "Ubiquiti UniFi" ...
I can write the file in it's entriety to a json object. But that's as far as I can get...
Json::Value root;
string line;
ifstream myfile( "/proc/cpuinfo" );
if (myfile)
{
while (getline( myfile, line ))
{
root["test"] = line;
cout << root;
}
myfile.close();
}
Which is close but obviously gives me json like so:
{
"test" : "system type : Atheros AR7241 rev 1"
}
Am new to c++ I don't know how to split the lines at the colon and use the first half for the key instead of "test".. Can someone suggest a way to go about this?