当前位置:编程学习 > JS >>

c++编写json解析类

好久没有更新博客了,今天就将我之前写的一些代码陆续发上来。

json.h

[cpp]
#include<iostream> 
#include <string> 
using namespace std; 
 
class CJson 

public: 
    enum TYPE{STRING,LONG,ARRAY,OBJECT,BOOL,NAMEDOBG,STRINGA,LONGA,ARRAYA,OBJECTA,BOOLA,NAMEDOBGA}; 
    typedef struct _NODE 
    { 
        friend CJson; 
        string m_key; 
        TYPE type; 
        string m_strVal; 
        bool m_boolVal; 
        long m_longVal; 
        string m_objVal; 
        _NODE(){memset(this,0,sizeof(_NODE));} 
        _NODE* GetChild(){return m_child;} 
        _NODE* GetNext(){return m_next;} 
        _NODE* GetParent(){return m_parent;} 
        _NODE* Get(int index) 
        { 
            NODE* n=m_child; 
            for(int i=0;i<index;i++) 
            { 
                if(n==0) 
                { 
                    return 0; 
                } 
                n=n->m_next; 
            } 
            return n; 
        } 
        _NODE* Get(char* key) 
        { 
            NODE* n=m_child; 
            while(n) 
            { 
                if(n->m_key==key) 
                { 
                    return n; 
                } 
                n=n->m_next; 
            } 
            return 0; 
        } 
        _NODE* Append(TYPE type,char* key,char* sVal,long nVal) 
        { 
            NODE *node=new NODE; 
            node->type=type; 
            if(type==STRING) 
            { 
                node->m_key=key; 
                node->m_strVal=sVal; 
            } 
            else if (type==LONG) 
            { 
                node->m_key=key; 
                node->m_longVal=nVal; 
            } 
            else if(type==OBJECT) 
            { 
                node->m_key=key; 
            } 
            else if (type==ARRAY) 
            { 
                node->m_key=key; 
            } 
            else if(type==STRINGA) 
            { 
                node->m_strVal=sVal; 
            } 
            else if (type==LONGA) 
            { 
                node->m_longVal=nVal; 
            } 
            else if(type==OBJECTA) 
            { 
 
            } 
            else if (type==ARRAYA) 
            { 
 
            } 
            if(!m_child) 
            { 
                m_child=node; 
                node->m_parent=this; 
            } 
            else 
            { 
          &

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,