专职C++

不能停止的脚步

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

常用链接

留言簿(28)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

因为要用到调试json的解析结果,所以在这里写了一个,结果近似json格式

void PrintJsonList(const string & paramPre, Json::Value & paramValue)
{
    Json::Value::Members mem = paramValue.getMemberNames();  
    for (auto iter = mem.begin(); iter != mem.end(); iter++)  
    {  
        cout<<paramPre<<"\""<<*iter<<"\":";  
        if (paramValue[*iter].type() == Json::objectValue)  
        {  
            cout<<paramPre<<"{"<<endl;  
            PrintJsonList(paramPre + "   ", paramValue[*iter]);  
            cout<<paramPre<<"},"<<endl;
        }  
        else if (paramValue[*iter].type() == Json::arrayValue)  
        {  
            cout<<paramPre<<"["<<endl;  
            auto cnt = paramValue[*iter].size();  
            for (auto i = 0; i < cnt; i++)  
            {  
                Json::Value & pElem = paramValue[*iter][i];
                if (pElem.type() == Json::arrayValue)
                {
                    cout <<paramPre<< "["<<endl;
                    PrintJsonList(paramPre + "   ", pElem);  
                    cout <<paramPre<< "],"<<endl;
                }
                else if (pElem.type() == Json::objectValue)
                {
                    cout <<paramPre<< "{"<<endl;
                    PrintJsonList(paramPre + "   ", pElem);  
                    cout <<paramPre<< "},"<<endl;
                }
                else PrintJsonList(paramPre + "   ", pElem);  
            }  
            cout<<paramPre<<"]"<<endl;  
        }  
        else if (paramValue[*iter].type() == Json::stringValue)  
        {  
            cout<<"\""<<paramValue[*iter].asString()<<"\""<<endl;  
        }  
        else if (paramValue[*iter].type() == Json::realValue)  
        {  
            cout<<paramValue[*iter].asDouble()<<endl;  
        }  
        else if (paramValue[*iter].type() == Json::uintValue)  
        {  
            cout<<paramValue[*iter].asUInt()<<endl;  
        }  
        else
        {  
            cout<<paramValue[*iter].asInt()<<endl;  
        }  
    }  
    return;  
}
posted on 2014-04-29 16:30 冬瓜 阅读(2229) 评论(0)  编辑 收藏 引用 所属分类: 原创

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理