프로그래밍/CPP

rapidjson 사용법 정리

스스배 2023. 3. 22. 09:52

http://rapidjson.org/md_doc_tutorial.html#ValueDocument

 

RapidJSON: Tutorial

This tutorial introduces the basics of the Document Object Model(DOM) API. As shown in Usage at a glance, JSON can be parsed into a DOM, and then the DOM can be queried and modified easily, and finally be converted back to JSON. Value & Document Each JSON

rapidjson.org

공식 참고 문서

 

일반 오브젝트 타입

Value MeshDesc(kObjectType);
MeshDesc.AddMember("m_ViewZ", 1.f, allocator);
MeshDesc.AddMember("m_eFormat", 0, allocator);

 

Array 타입

Value Meshs(kArrayType);
    {
	 for (size_t i = 0; i < m_Meshes.size(); ++i)
        {
        	Value MeshDesc(kObjectType);
            MeshDesc.AddMember("m_iMaterialIndex", m_Meshes[i]->Get_MaterialIndex(), allocator);
            Meshs.PushBack(MeshDesc, allocator);
        }
        
     }

주의 할 점이 반드시 for안에서 해당 array타입에 들어갈 객체를 만들고 

for의 끝나는 시점에서 그 객체를 넣어줘야함

 

for밖에서 array에 들어갈 객체를 만들거나 객체 밖에서 pushBack해주면 무조건 에러 발생함

 

3. String 객체

Value szName;
string	meshName = m_Meshes[i]->Get_Name();
szName.SetString(meshName.c_str(), (SizeType)meshName.size(), allocator);
MeshDesc.AddMember("szName", szName, allocator);