How to store data into a Map from json file #2692
-
What is the issue you have?I'm having a json file as follows: [
{
"top__DOT__comp_ac_Multiplier_Mux01__DOT__H11TW040L_UCVCSND2X010_Z_s": [
"sa0",
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__INDEX02_Outp_s": [
"sa0",
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSND2X010__DOT__NOT00_Outp_s": [
"sa0"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSND2X010__DOT__NOT01_Outp_s": [
"sa0"
]
},
{
"top__DOT__comp_ac_Multiplier_Mux01__DOT__H11TW040L_UCVCSAORI1X010_Z_s": [
"sa0",
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__INDEX00_Outp_s": [
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__INDEX01_Outp_s": [
"sa1"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSAORI1X010__DOT__BAND_Outp_s": [
"sa0"
],
"top__DOT__comp_ac_Multiplier_Mux01__DOT__comp_H11TW040L_UCVCSAORI1X010__DOT__NOT_Outp_s": [
"sa0"
]
}
] It is a list of dictionaries. I want to read this file and store each dictionary into a map of vectors. Later I have to iterate over the each dictionary and extract key and values(which is a list in this case). I have used the following code to do this: class faults{
map<string, vector<string>> myMap;
};
std::ifstream myinput("fault_list.json");
auto j = json::parse(myinput);
std::vector<faults> fault = j; I'm facing the following error: Operating System: Unix I used the json.hpp file from here Kindly help me with the issue. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to define a conversion from JSON to your type |
Beta Was this translation helpful? Give feedback.
You need to define a conversion from JSON to your type
faults
. See https://github.com/nlohmann/json#arbitrary-types-conversions for guidance.