I want to parse json file and store it in C++ classes. I need help understanding what is the best way to achieve this?
test.json
{
"vehicles": [
{
"type" : "car" :
{
"car1" :
{
"name" : "merc-cla250",
"color" : "black",
},
"car2" :
{
"name" : "toyota-prius",
"color" : "blue",
},
}
},
{
"type" : "bike" :
{
"bike1" :
{
"name" : "windsor",
"color : "black",
},
"bike2" :
{
"name" : "diamond",
"color : "black",
},
}
}
]
}
I want to store these info in classes in C++. In C, I would have defined few structures and stored the info. I am learning C++. Firstly, I just wanted to design header file. I tried following things. Can someone help me improving this? I know, I have written like C style but I appreciate if someone can help me writing better C++ way. Once, I will write the header file, I will start writing cpp file. Thanks in advance! Appreciate your time and help!
vehicle_json.h
#ifndef __VEHICLE_H__
#define __VEHICLE_H__
#include <iostream>
#include <cstdlib>
class vehicle
{
public:
const std::string& getType(void);
private:
std::string type;
carList& carsInfo; // Can I do this?
bikeList& bikesInfo;
};
class car
{
public:
const std::string& getName(void);
const std::string& getType(void);
private:
std::string name;
std::string color;
};
typedef std::vector<car> carList;
class bike
{
public:
const std::string& getName(void);
const std::string& getType(void);
private:
std::string name;
std::string color;
};
typedef std::vector<bike> bikeList;
#endif // __VEHICLE_H__