String written to JSON file

Source: Internet
Author: User

Background: PHP generates announcements that are sent to CGI, where CGI writes JSON strings of the announcement to the file (the escaped string)

Operation via Jsoncpp

    intWrite_notice_to_json (stringStr_path,Const string&str_content)        {Json::reader Reader;        Json::fastwriter writer;        Json::value Root; if(false= = Reader.parse (str_content, Root))//Reader parses the JSON string into root,root will contain all the child elements in the JSON        {            returnResult_error; } std::stringJson_file =Writer.write (root);        Ofstream OFS; Ofs.open (Str_path.c_str (), Ofstream:: out); if(Ofs.is_open ()) {OFS<<Json_file;             Ofs.close (); returnRESULT_OK; }         returnResult_error; }  

Came to the company today and finally got the mark.

The string content received:

{\ "notice\": {\ "noticeversion\": \ "1414\", \ "noticecontent\": [{\ "image\": \ "notice\\/notice01\", \ "imagewidth\": \ " 350\ ", \" imageheight\ ": \" 5\ "},{\" image\ ": \" notice\\/notice02\ ", \" imagewidth\ ": \" 350\ ", \" imageheight\ ": \" 5\ "},\" Jghjfghjfghj\ "]}}

After saving to file

Trampled pit: Initially wanted to replace the reversed string with C + + but it didn't work

Cstringutils::replace (m_str_content, "\\\" "," \ "");

String written to JSON file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.