-
[C++, rapidjson] AddMember 시의 형변환 문제프로그래밍/C++ 2019. 5. 14. 13:06
rapidjson 을 사용해 array 형태의 json message 를 만들다보니..
내가 원하는건 std::string 을 사용해서 A :{[B:C, D:F]} 형태로 모두 string 으로 이뤄진 배열을 만드는 것.
rapidjson::Document tempres;
tempres.SetObject();
rapidjson::Value integrityArray(rapidjson::kArrayType);
rapidjson::Document::AllocatorType& allocator = tempres.GetAllocator();
for (auto iter : *objArray) {
rapidjson::Value objValue;
rapidjson::Value strValue;
objValue.SetObject();
strValue.SetString(iter.Name.c_str(), iter.Name.length(), allocator);
objValue.AddMember("filePath", strValue, allocator); //처음엔 strValue 안쓰고, 그냥 바로 iter.Name 넣었는데 안됨.
strValue.SetString(iter.NewHash.c_str(), iter.NewHash.length(), allocator);
objValue.AddMember("hash", strValue, allocator);
integrityArray.PushBack(objValue, allocator);
}이렇게 하면, AddMember 쪽에서 GenericValue 부분의 T를 형변환을 제대로 하지 못해서 error가 발생.
그래서 검색하다보니...
rapidjson 을 include 하기 전에,
#define RAPIDJSON_HAS_STDSTRING 1
위의 한 줄만 define 해주니까 error 해결. 일단은 넘어갔다!!
몇 시간 삽질을 한건지... 별 수를 다 써봐도 안되던게 해결됨.
출처 : https://stackoverflow.com/questions/34573940/how-can-i-add-string-pairs-to-a-document-of-rapidjson
'프로그래밍 > C++' 카테고리의 다른 글
[C, C++, File] fprintf를 이용한 로깅 관련 매크로 작성 (0) 2019.07.04 [c++, VS2013] Visual Studio 2013 Error: c4996 this function or variable may be unsafe (0) 2019.05.24 [C++] std::string convert std::wstring (0) 2019.05.14 [MFC] CString <-> LPCSTR 변환 (0) 2016.12.24 [MFC] CString 문자열의 Delete 함수 (0) 2016.12.20