C++ boost 解析 Json

本文涉及的产品
全局流量管理 GTM,标准版 1个月
云解析 DNS,旗舰版 1个月
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
简介: property_tree可以解析ini,xml,json,info等格式的文本 以下示例是解析json格式的文本 #include <iostream>#include <stdlib.h>#include <stdio.h>#include <string>#include <sstream>#incl



property_tree可以解析ini,xml,json,info等格式的文本
以下示例是解析json格式的文本

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <time.h>

using namespace std;
using namespace boost::property_tree;


const string file_path = "c:\\test.txt";

void write_json_data_into_file(void)
{
    printf("%s\n","write json data");

    boost::property_tree::ptree root, items;

    boost::property_tree::ptree item1;
    item1.put("ID","1");
    item1.put("Name","wang");
    items.push_back(std::make_pair("1",item1));

    boost::property_tree::ptree item2;
    item2.put("ID","2");
    item2.put("Name","zhang");
    items.push_back(std::make_pair("2",item2));

    root.put_child("users",items);
    boost::property_tree::write_json(file_path,root);
}

void read_json_data_from_file(void)
{
    printf("%s\n","read json data");
    boost::property_tree::ptree root;
    boost::property_tree::ptree items;
    boost::property_tree::read_json<boost::property_tree::ptree>(file_path,root);

    items = root.get_child("users");
    for(boost::property_tree::ptree::iterator it=items.begin(); it != items.end(); ++it)
    {
        string key=it->first;//key ID
        string ID=it->second.get<string>("ID");
        string Name=it->second.get<string>("Name");
        cout<<"key: "<<key.c_str()<<'\t';
        printf("ID: %s    Name: %s",ID.c_str(), Name.c_str());
        cout<<endl;
        cout<<"ID:"<<ID<<'\t'<<"Name:"<<Name<<endl;
    }
    cout<<"success"<<endl;
}

void write_json_data_into_string(void)
{
    boost::property_tree::ptree item;
    item.put("a","2");
    std::stringstream is;
    boost::property_tree::write_json(is,item);
    std::string s = is.str();
    cout<<"json s:"<<s<<endl;
}

void read_json_data_from_string(void)
{
    /*
        C++ 中 字符串形式的json串 需要使用 \ 转义 双引号
    */
    std::string str_json = "{\"count\":10,\"people\":[{ \"firstName\": \"Brett\", \"lastName\":\"McLaughlin\", \"email\": \"aaaa\" },{ \"firstName\": \"Jason\", \"lastName\":\"Hunter\", \"email\": \"bbbb\"},{ \"firstName\": \"Elliotte\", \"lastName\":\"Harold\", \"email\": \"cccc\" }]}";
    std::stringstream str_stream(str_json);
    boost::property_tree::ptree root;
    boost::property_tree::read_json(str_stream,root);
    root.put("upid","001");

    // 插入一个数组
    boost::property_tree::ptree exif_array;
    boost::property_tree::ptree array1, array2, array3;
    array1.put("Make", "NIKON");
    array2.put("DateTime", "2011:05:31 06:47:09");
    array3.put("Software", "Ver.1.01");

    //   exif_array.push_back(std::make_pair("Make", "NIKON"));
    //   exif_array.push_back(std::make_pair("DateTime", "2011:05:31 06:47:09"));
    //   exif_array.push_back(std::make_pair("Software", "Ver.1.01"));

    exif_array.push_back(std::make_pair("", array1));
    exif_array.push_back(std::make_pair("", array2));
    exif_array.push_back(std::make_pair("", array3));

    root.put_child("exifs", exif_array);
    std::stringstream str_stream_temp;
    boost::property_tree::write_json(str_stream_temp, root);
    //write_json(str_stream_temp, root);
    std::string str = str_stream_temp.str();
    cout<<str<<endl;
}


void testMsg(void)
{
    string str_json = "{\"TEST\":\"\",\"MSG\":\"130\",\"TKT\":[{\"DTYP\":\"T\",\"STOT\":\"1\",\"SNUM\":\"1\",\"CPN\":[{\"CNBR\":\"1\",\"DDAT\":\"090117\",\"DTME\":\"1205\",\"ADAT\":\"090117\",\"ATME\":\"1340\",\"ORIG\":\"TSA\",\"DEST\":\"PVG\",\"ALC1\":\"FM\",\"FLTN\":\"802\",\"CLAS\":\"Y\",\"FSTN\":\"OK\",\"FBAS\":\"Y\",\"BAGA\":\"20K\"}]}]}";
    std::stringstream str_stream(str_json);
    boost::property_tree::ptree root;
    boost::property_tree::read_json(str_stream,root);
    boost::property_tree::ptree::iterator root_it = root.begin();
    for(; root_it != root.end(); ++root_it)
    {
        string key = root_it->first;
        if("TKT" == key)
        {
            boost::property_tree::ptree tkt_node = root.get_child(key);
            boost::property_tree::ptree::iterator tkt_node_it = tkt_node.begin();
            for(; tkt_node_it != tkt_node.end(); ++tkt_node_it)
            {
                boost::property_tree::ptree tkt = tkt_node_it->second;
                boost::property_tree::ptree::iterator tkt_it = tkt.begin();
                for(; tkt_it != tkt.end(); ++tkt_it)
                {
                    string tkt_key = tkt_it->first;
                    if("CPN" == tkt_key)
                    {
                        boost::property_tree::ptree cpn_node = tkt.get_child(tkt_key);
                        boost::property_tree::ptree::iterator cpn_node_it = cpn_node.begin();
                        for(; cpn_node_it != cpn_node.end(); ++cpn_node_it)
                        {
                            boost::property_tree::ptree cpn = cpn_node_it->second;
                            boost::property_tree::ptree::iterator cpn_it = cpn.begin();
                            for(; cpn_it != cpn.end();++cpn_it)
                            {
                                string cpn_key = cpn_it->first;
                                string cpn_val = cpn.get<string>(cpn_key);
                                cout<<cpn_key<<":"<<cpn_val<<endl;
                            }
                        }
                    }
                    else
                    {
                        string tkt_val = tkt.get<string>(tkt_key);
                        cout << tkt_key << ":"<<tkt_val<<endl;
                    }
                }
            }
        }
        else
        {
            string val = root.get<string>(key);
            cout << key <<":"<< val <<endl;
            //Sleep(1000);
        }

    }
}

void bianli_json(void)
{
    string json_string="{\"-f\": \"/usr/reservedfff_dir\", \"-s\": \"/usr/reservedddd_dir\"}";

    string str_head;
    string str_node_val;
    boost::property_tree::ptree pt,p1,p2;

    stringstream stream(json_string);
    try
    {
        boost::property_tree::read_json<boost::property_tree::ptree>(stream, pt);
        cout<<"parsing ok\n"<<endl;
        for (boost::property_tree::ptree::iterator ita = pt.begin(); ita != pt.end(); ++ita)
        {
            cout<<"first:"<<ita->first<<endl;
            str_node_val = pt.get<string>(ita->first);
            cout<<str_node_val<<endl;
        }
    }
    catch(std::runtime_error& e)
    {
        std::cout<<e.what()<<endl;
    }
}

void test(void)
{
    string str_json = "{\"TEST\":\"\",\"MSG\":\"130\",\"TKT\":[{\"DTYP\":\"T\",\"STOT\":\"1\",\"SNUM\":\"1\",\"CPN\":[{\"CNBR\":\"1\",\"DDAT\":\"090117\",\"DTME\":\"1205\",\"ADAT\":\"090117\",\"ATME\":\"1340\",\"ORIG\":\"TSA\",\"DEST\":\"PVG\",\"ALC1\":\"FM\",\"FLTN\":\"802\",\"CLAS\":\"Y\",\"FSTN\":\"OK\",\"FBAS\":\"Y\",\"BAGA\":\"20K\"}]}]}";
    std::stringstream str_stream(str_json);
    boost::property_tree::ptree root;
    boost::property_tree::read_json(str_stream,root);

    boost::property_tree::ptree tkt = root.get_child("TKT");
    stringstream tkt_stream;
    boost::property_tree::write_json(tkt_stream, tkt);
    cout<<tkt_stream.str()<<endl; //通过打印可以看到 first 为空

    for(boost::property_tree::ptree::iterator it = tkt.begin(); it!=tkt.end();++it)
    {
        boost::property_tree::ptree inner = it->second; //first为空
        //string DTYP_val = inner.get<string>("DTYP");
        //cout << "DTYP" <<":"<< DTYP_val<<endl;

        boost::property_tree::ptree::iterator it_tkt = inner.begin();
        for(; it_tkt != inner.end(); ++it_tkt)
        {
            string innet_key = it_tkt->first;
            cout<<innet_key<<":"<<inner.get<string>(innet_key)<<endl;
        }
        break;
    }

    //    boost::property_tree::ptree pt,pptt,ttt;
    //    string s = "{\"data\":[{\"id\":1,\"name\":\"chen\"},{\"id\":2,\"name\":\"zhang\"}]}";
    //    stringstream stream(s);
    //    read_json(stream, pt);

    //    pptt = pt.get_child("data");
    //    for (boost::property_tree::ptree::iterator it = pptt.begin(); it != pptt.end(); ++it)
    //    {
    //        ttt = it->second; //first为空
    //        cout<<"id="<<ttt.get<string>("id")<<endl;
    //        cout<<"name="<<ttt.get<string>("name")<<endl;
    //    }
}

void parseMsg_1(void)
{
    string msg_str = "{\"MSG\":\"130\",\"CRSC\":\"MU\",\"CRSL\":\"BJS\",\"TAID\":\"08692057\",\"IHID\":\"PEK112\",\"ORGT\":\"A\",\"CRSN\":\"9995\",\"IHIB\":\"PEK112\",\"IDTP\":\"B\",\"PNR1\":\"NYFY37\",\"PNR2\":\"MU\",\"SURN\":\"zhang\",\"GIVN\":\"san\",\"FMID\":\"PPG19739941\",\"DTIS\":\"030117\",\"JORG\":\"TPE\",\"JDST\":\"MAD\",\"FAMT\":\"1560.00\",\"FCUR\":\"CNY\",\"TAMT\":\"1660.00\",\"TCUR\":\"CNY\",\"FANF\":\"H/1560.00/CNY+G/00:00/CNY\",\"FOPF\":\"CC\",\"TAXF\":\"T/CNY/50.00/CN+T/CNY/50.00/YQ\",\"FACF\":\"M/09JAN17TSA FM PVG MU JFK/-GRU JJ MAD1560.00CNY1560.00END\",\"TKT\":[{\"DTYP\":\"T\",\"STOT\":\"1\",\"SNUM\":\"1\",\"CPN\":[{\"CNBR\":\"1\",\"DDAT\":\"090117\",\"DTME\":\"1205\",\"ADAT\":\"090117\",\"ATME\":\"1340\",\"ORIG\":\"TSA\",\"DEST\":\"PVG\",\"ALC1\":\"FM\",\"FLTN\":\"802\",\"CLAS\":\"Y\",\"FSTN\":\"OK\",\"FBAS\":\"Y\",\"BAGA\":\"20K\"},{\"CNBR\":\"1\",\"DDAT\":\"090117\",\"DTME\":\"1205\",\"ADAT\":\"090117\",\"ATME\":\"1340\",\"ORIG\":\"TSA\",\"DEST\":\"PVG\",\"ALC1\":\"FM\",\"FLTN\":\"802\",\"CLAS\":\"Y\",\"FSTN\":\"OK\",\"FBAS\":\"Y\",\"BAGA\":\"20K\"}]},{\"DTYP\":\"T\",\"STOT\":\"1\",\"SNUM\":\"1\",\"CPN\":[{\"CNBR\":\"1\",\"DDAT\":\"090117\",\"DTME\":\"1205\",\"ADAT\":\"090117\",\"ATME\":\"1340\",\"ORIG\":\"TSA\",\"DEST\":\"PVG\",\"ALC1\":\"FM\",\"FLTN\":\"802\",\"CLAS\":\"Y\",\"FSTN\":\"OK\",\"FBAS\":\"Y\",\"BAGA\":\"20K\"}]}]}";
    stringstream msg_ss(msg_str);
    boost::property_tree::ptree msg;
    boost::property_tree::read_json(msg_ss, msg);
    boost::property_tree::ptree::iterator msg_it = msg.begin();
    for(; msg_it != msg.end(); ++msg_it)
    {
        string msg_key = msg_it->first;
        string val = "";
        if("TKT" == msg_key)
        {
            boost::property_tree::ptree tkt_node = msg.get_child(msg_key);
            boost::property_tree::ptree::iterator tkt_node_it = tkt_node.begin();
            for(; tkt_node_it != tkt_node.end(); ++tkt_node_it)
            {
                boost::property_tree::ptree tkt = tkt_node_it->second;
                boost::property_tree::ptree::iterator tkt_it = tkt.begin();
                for(; tkt_it != tkt.end(); ++tkt_it)
                {
                    string tkt_key = tkt_it->first;
                    if("CPN" == tkt_key)
                    {
                        boost::property_tree::ptree cpn_node = tkt.get_child(tkt_key);
                        boost::property_tree::ptree::iterator cpn_node_it = cpn_node.begin();
                        for(; cpn_node_it != cpn_node.end(); ++cpn_node_it)
                        {
                            boost::property_tree::ptree cpn = cpn_node_it->second;
                            boost::property_tree::ptree::iterator cpn_it = cpn.begin();
                            for(; cpn_it != cpn.end(); ++cpn_it)
                            {
                                string cpn_key = cpn_it->first;
                                val = cpn.get<string>(cpn_key);
                                cout << cpn_key << ":" << val <<endl;
                            }
                        }
                    }
                    else
                    {
                        val = tkt.get<string>(tkt_key);
                        cout<< tkt_key << ":" << val <<endl;
                    }
                }
            }
        }
        else
        {
            val = msg.get<string>(msg_key);
            cout<< msg_key<<":"<<val<<endl;
        }
    }

}

void parseMsg(void)
{
    string msg_str = "{\"MSG\":\"MSG\",\"CRSC\":\"CRSC\",\"CRSL\":\"CRSL\",\"TAID\":\"TAID\",\"IHID\":\"IHID\",\"ORGT\":\"ORGT\",\"CRSN\":\"CRSN\",\"IHIB\":\"IHIB\",\"IDTP\":\"IDTP\",\"PNR1\":\"PNR1\",\"PNR2\":\"PNR2\",\"TIF\":[{\"SURN\":\"SURN\",\"GIVN\":\"GIVN\",\"FMID\":\"FMID\",\"INFP\":\"INFP\",\"UMCH\":\"UMCH\",\"JORG\":\"JORG\",\"JDST\":\"JDST\",\"FAMT\":\"FAMT\",\"FCUR\":\"FCUR\",\"TAMT\":\"TAMT\",\"TCUR\":\"TCUR\",\"FANF\":\"FANF\",\"FOPF\":\"FOPF\",\"TAXF\":\"TAXF\",\"TKT\":[{\"TKNB\":\"TKNB\",\"STOT\":\"STOT\",\"SNUM\":\"SNUM\",\"CPN\":[{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"},{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"}]},{\"TKNB\":\"TKNB\",\"STOT\":\"STOT\",\"SNUM\":\"SNUM\",\"CPN\":[{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"},{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"}]}]},{\"SURN\":\"SURN\",\"GIVN\":\"GIVN\",\"FMID\":\"FMID\",\"INFP\":\"INFP\",\"UMCH\":\"UMCH\",\"JORG\":\"JORG\",\"JDST\":\"JDST\",\"FAMT\":\"FAMT\",\"FCUR\":\"FCUR\",\"TAMT\":\"TAMT\",\"TCUR\":\"TCUR\",\"FANF\":\"FANF\",\"FOPF\":\"FOPF\",\"TAXF\":\"TAXF\",\"TKT\":[{\"TKNB\":\"TKNB\",\"STOT\":\"STOT\",\"SNUM\":\"SNUM\",\"CPN\":[{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"},{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"}]},{\"TKNB\":\"TKNB\",\"STOT\":\"STOT\",\"SNUM\":\"SNUM\",\"CPN\":[{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"},{\"CNBR\":\"CNBR\",\"DDAT\":\"DDAT\",\"DTME\":\"DTME\",\"ADAT\":\"ADAT\",\"ATME\":\"ATME\",\"ORIG\":\"ORIG\",\"DEST\":\"DEST\",\"ALC1\":\"ALC1\",\"FLTN\":\"FLTN\",\"CLAS\":\"CLAS\",\"FSTN\":\"FSTN\",\"FBAS\":\"FBAS\",\"BAGA\":\"BAGA\"}]}]}]}";
    stringstream msg_ss(msg_str);
    ptree msg;
    read_json(msg_ss, msg);
    string val = "";
    for(ptree::iterator msg_it = msg.begin(); msg_it != msg.end(); ++msg_it)
    {
        string msg_key = msg_it->first;
        if("TIF" == msg_key)
        {
            ptree tif_node = msg.get_child(msg_key);
            for(ptree::iterator tif_node_it = tif_node.begin(); tif_node_it != tif_node.end(); ++tif_node_it)
            {
                ptree tif = tif_node_it->second;
                for(ptree::iterator tif_it = tif.begin(); tif_it != tif.end(); ++tif_it)
                {
                    string tif_key = tif_it->first;
                    if("TKT" == tif_key)
                    {
                        ptree tkt_node = tif.get_child(tif_key);
                        for(ptree::iterator tkt_node_it = tkt_node.begin(); tkt_node_it != tkt_node.end(); ++tkt_node_it)
                        {
                            ptree tkt = tkt_node_it->second;
                            for(ptree::iterator tkt_it = tkt.begin(); tkt_it != tkt.end(); ++tkt_it)
                            {
                                string tkt_key = tkt_it->first;
                                if("CPN" == tkt_key)
                                {
                                    ptree cpn_node = tkt.get_child(tkt_key);
                                    for(ptree::iterator cpn_node_it = cpn_node.begin(); cpn_node_it != cpn_node.end(); ++cpn_node_it)
                                    {
                                        ptree cpn = cpn_node_it->second;
                                        for(ptree::iterator cpn_it = cpn.begin(); cpn_it != cpn.end(); ++cpn_it)
                                        {

                                            string cpn_key = cpn_it->first;
                                            val = cpn.get<string>(cpn_key);
                                            cout<< cpn_key <<":"<<val<<endl;
                                        }
                                    }
                                }
                                else
                                {

                                    val = tkt.get<string>(tkt_key);
                                    cout<<tkt_key<<":"<<val<<endl;
                                }
                            }
                        }
                    }
                    else
                    {

                        val = tif.get<string>(tif_key);
                        cout<< tif_key << ":" <<val <<endl;
                    }
                }
            }
        }
        else
        {

            val = msg.get<string>(msg_key);
            cout<< msg_key << ":" <<val<<endl;
        }
    }
}


int main()
{
    //    write_json_data_into_file();
    //    system("pause");
    //    read_json_data_from_file();
    //    system("pause");
    //    write_json_data_into_string();
    //    system("pause");
    //    read_json_data_from_string();
    cout<<"---------------------------"<<endl;
    testMsg();
    cout<<"---------------------------"<<endl;
    bianli_json();
    cout<<"---------------------------"<<endl;
    test();
    cout<<"---------------------------"<<endl;
    parseMsg();
    return 0;
}





目录
相关文章
|
2月前
|
SQL 存储 JSON
SQL,解析 json
SQL,解析 json
80 8
|
1月前
|
自然语言处理 编译器 Linux
|
1月前
|
设计模式 安全 数据库连接
【C++11】包装器:深入解析与实现技巧
本文深入探讨了C++中包装器的定义、实现方式及其应用。包装器通过封装底层细节,提供更简洁、易用的接口,常用于资源管理、接口封装和类型安全。文章详细介绍了使用RAII、智能指针、模板等技术实现包装器的方法,并通过多个案例分析展示了其在实际开发中的应用。最后,讨论了性能优化策略,帮助开发者编写高效、可靠的C++代码。
38 2
|
10天前
|
安全 编译器 C++
C++ `noexcept` 关键字的深入解析
`noexcept` 关键字在 C++ 中用于指示函数不会抛出异常,有助于编译器优化和提高程序的可靠性。它可以减少代码大小、提高执行效率,并增强程序的稳定性和可预测性。`noexcept` 还可以影响函数重载和模板特化的决策。使用时需谨慎,确保函数确实不会抛出异常,否则可能导致程序崩溃。通过合理使用 `noexcept`,开发者可以编写出更高效、更可靠的 C++ 代码。
16 0
|
10天前
|
存储 程序员 C++
深入解析C++中的函数指针与`typedef`的妙用
本文深入解析了C++中的函数指针及其与`typedef`的结合使用。通过图示和代码示例,详细介绍了函数指针的基本概念、声明和使用方法,并展示了如何利用`typedef`简化复杂的函数指针声明,提升代码的可读性和可维护性。
39 0
|
1月前
|
自然语言处理 编译器 Linux
告别头文件,编译效率提升 42%!C++ Modules 实战解析 | 干货推荐
本文中,阿里云智能集团开发工程师李泽政以 Alinux 为操作环境,讲解模块相比传统头文件有哪些优势,并通过若干个例子,学习如何组织一个 C++ 模块工程并使用模块封装第三方库或是改造现有的项目。
|
2月前
|
缓存 网络协议 API
C/C++ StringToAddress(字符串转 boost::asio::ip::address)
通过上述步骤和示例代码,你可以轻松地在C++项目中实现从字符串到 `boost::asio::ip::address`的转换,从而充分利用Boost.Asio库进行网络编程。
89 0
|
2月前
|
JSON JavaScript API
商品详情数据接口解析返回的JSON数据(API接口整套流程)
商品详情数据接口解析返回的JSON数据是API接口使用中的一个重要环节,它涉及从发送请求到接收并处理响应的整个流程。以下是一个完整的API接口使用流程,包括如何解析返回的JSON数据:
|
1月前
|
监控 Java 应用服务中间件
高级java面试---spring.factories文件的解析源码API机制
【11月更文挑战第20天】Spring Boot是一个用于快速构建基于Spring框架的应用程序的开源框架。它通过自动配置、起步依赖和内嵌服务器等特性,极大地简化了Spring应用的开发和部署过程。本文将深入探讨Spring Boot的背景历史、业务场景、功能点以及底层原理,并通过Java代码手写模拟Spring Boot的启动过程,特别是spring.factories文件的解析源码API机制。
77 2
|
3天前
|
存储 设计模式 算法
【23种设计模式·全精解析 | 行为型模式篇】11种行为型模式的结构概述、案例实现、优缺点、扩展对比、使用场景、源码解析
行为型模式用于描述程序在运行时复杂的流程控制,即描述多个类或对象之间怎样相互协作共同完成单个对象都无法单独完成的任务,它涉及算法与对象间职责的分配。行为型模式分为类行为模式和对象行为模式,前者采用继承机制来在类间分派行为,后者采用组合或聚合在对象间分配行为。由于组合关系或聚合关系比继承关系耦合度低,满足“合成复用原则”,所以对象行为模式比类行为模式具有更大的灵活性。 行为型模式分为: • 模板方法模式 • 策略模式 • 命令模式 • 职责链模式 • 状态模式 • 观察者模式 • 中介者模式 • 迭代器模式 • 访问者模式 • 备忘录模式 • 解释器模式
【23种设计模式·全精解析 | 行为型模式篇】11种行为型模式的结构概述、案例实现、优缺点、扩展对比、使用场景、源码解析

热门文章

最新文章

推荐镜像

更多