dimanche 4 novembre 2018

C++ way to remove double quotes from the key part (in key:value) of a JSON string

In the below JSON buffer snippet i want to replace the (double quotes ") around the key - "Key" to have no double quotes. like

"\"Key1\" = \"Val1\", \"Key2\" = \"Val2\", \"Key3\" = \"val3\", \"key4\" = \"val4\", \"key5\" = \"val5\""

TO

Key1 = \"Val1\", Key2 = \"Val2\", Key3 = \"val3\", key4 = \"val4\", key5 = \"val5\"

#include<iostream>
            #include <string>

            int main()
            {
                std::string str = "\"Key1\" = \"Val1\", \"Key2\" = \"Val2\", \"Key3\" = \"val3\", \"key4\" = \"val4\", \"key5\" = \"val5\"";

         std::string formattedStr = FormatTheString(str);
    //Output of this above statement should be 
    //  Key1 = \"Val1\", Key2 = \"Val2\", Key3 = \"val3\", key4 = \"val4\", key5 = \"val5\"

                return 0;
            }

I know i can do this by performing string/character operations but I was looking for a clean C++ way of doing this. Can i use regex library or any clean C++ way to do this.

Aucun commentaire:

Enregistrer un commentaire