• 大小: 1.36MB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2023-08-27
  • 语言: C/C++
  • 标签: Json  c++  obj  

资源简介

json 字符串转成c++类对象,json 字符串转成c++类对象

资源截图

代码片段和文件信息

#include “IParseJson.h“
#include  // sort
#include 
#include 
#include 
IParseJson* IParseJson::CreateJsonItem( string strKey )
{
    return this;
}

void IParseJson::PrintValueTree( Json::Value &value IParseJson* pParent IParseJson* pobj const std::string strkey )
{
    IParseJson* pTmpJsonNode = NULL;
    switch ( value.type() )
    {
        case Json::nullValue:
            {
                break;
            }
        case Json::intValue:
            pobj->DealJsonNode( strkey value.asInt() );
            break;
        case Json::uintValue:
            pobj->DealJsonNode( strkey value.asUInt() );
            break;
        case Json::realValue:
            pobj->DealJsonNode( strkey value.asDouble() );
            break;
        case Json::stringValue:
            pobj->DealJsonNode( strkey value.asString() );
            break;
        case Json::booleanValue:
            pobj->DealJsonNode( strkey value.asBool() );
            break;
        case Json::arrayValue:
            {
                int size = value.size();

                for ( int index =0; index < size; ++index )
                {
                    pTmpJsonNode = pParent->CreateJsonItem( strkey );
                    PrintValueTree( value[index] pParent pTmpJsonNode strkey );
                }

            }
            break;
        case Json::objectValue:
            {
                Json::Value::Members members( value.getMemberNames() );
                std::sort( members.begin() members.end() );
                std::string suffix = ““;
                for ( Json::Value::Members::iterator it = members.begin();
                        it != members.end();
                        ++it )
                {
                    const std::string &name = *it;

                    PrintValueTree( value[name] pobj pobj name );

                }
            }
            break;
        default:
            break;
    }
}



BOOL IParseJson::ParseJson( const char* json )
{

    Json::Features features;
    Json::Reader reader( features );
    Json::Value root;
    bool parsingSuccessful = reader.parse( json root );
    if ( !parsingSuccessful )
    {
        return FALSE;
    }

    PrintValueTree( root this this  ““ );
    return TRUE;
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-05-09 16:52  Json_Obj_demo\
     目录           0  2014-05-09 16:47  Json_Obj_demo\Debug\
     文件        3046  2014-05-09 16:47  Json_Obj_demo\Debug\cl.command.1.tlog
     文件       45628  2014-05-09 16:47  Json_Obj_demo\Debug\CL.read.1.tlog
     文件        5578  2014-05-09 16:47  Json_Obj_demo\Debug\CL.write.1.tlog
     文件      308183  2014-05-09 16:40  Json_Obj_demo\Debug\IParseJson.obj
     文件         406  2014-05-09 16:40  Json_Obj_demo\Debug\Json_Obj_demo.exe.embed.manifest
     文件         472  2014-05-09 16:40  Json_Obj_demo\Debug\Json_Obj_demo.exe.embed.manifest.res
     文件         381  2014-05-09 16:47  Json_Obj_demo\Debug\Json_Obj_demo.exe.intermediate.manifest
     文件          76  2014-05-09 16:47  Json_Obj_demo\Debug\Json_Obj_demo.lastbuildstate
     文件        2504  2014-05-09 16:47  Json_Obj_demo\Debug\Json_Obj_demo.log
     文件      626810  2014-05-09 16:47  Json_Obj_demo\Debug\Json_Obj_demo.obj
     文件         216  2014-05-09 16:40  Json_Obj_demo\Debug\Json_Obj_demo_manifest.rc
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link-cvtres.read.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link-cvtres.write.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5456-cvtres.read.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5456-cvtres.write.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5456.read.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5456.read.2.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5456.write.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5580-cvtres.read.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5580-cvtres.write.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5580.read.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5580.read.2.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5580.write.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5652-cvtres.read.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5652-cvtres.write.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5652.read.1.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5652.read.2.tlog
     文件           2  2014-05-09 16:47  Json_Obj_demo\Debug\link.5652.write.1.tlog
     文件        2394  2014-05-09 16:47  Json_Obj_demo\Debug\link.command.1.tlog
............此处省略45个文件信息

评论

共有 条评论