
MongoDBBSONPackedArray::toRelaxedExtendedJSON 함수는 BSON 문서의 packed array 형식을 Extended JSON 형식으로 변환하는 함수입니다.
이 함수는 BSON 문서의 packed array 형식의 데이터를 받을 수 있으며, 반환하는 결과는 Extended JSON 형식의 문자열입니다.
이 함수를 사용하여 데이터를 변환할 때, null 값을 처리하는 방법은 다음과 같습니다.
- null 값을 포함하는 packed array를 Extended JSON 형식으로 변환할 때, null 값은 "null"로 표현됩니다.
예를 들어, 다음 코드를 사용하였을 때, 문제가 발생하는 이유는 다음과 같습니다.
#hostingforum.kr
cpp
BSONObj obj;
obj.append("field1", 1);
obj.append("field2", nullptr);
MongoDBBSONPackedArray arr = obj.getField("field2").asArray();
std::string json = arr.toRelaxedExtendedJSON();
이 코드에서는 null 값을 포함하는 packed array를 Extended JSON 형식으로 변환할 때, null 값은 "null"로 표현됩니다.
#hostingforum.kr
json
{
"field2" : [ null ]
}
이 코드는 정상적으로 작동합니다.
만약 null 값을 포함하는 packed array를 Extended JSON 형식으로 변환할 때, null 값을 생략하고 싶다면, toRelaxedExtendedJSON 함수에 옵션을 지정할 수 있습니다.
#hostingforum.kr
cpp
std::string json = arr.toRelaxedExtendedJSON(nullptr);
이 옵션은 null 값을 생략하는 옵션입니다.
#hostingforum.kr
json
{
"field2" : []
}
이 코드는 정상적으로 작동합니다.
만약 null 값을 포함하는 packed array를 Extended JSON 형식으로 변환할 때, null 값을 포함하고 싶다면, toRelaxedExtendedJSON 함수에 옵션을 지정할 수 있습니다.
#hostingforum.kr
cpp
std::string json = arr.toRelaxedExtendedJSON(BSONObj());
이 옵션은 null 값을 포함하는 옵션입니다.
#hostingforum.kr
json
{
"field2" : [ null ]
}
이 코드는 정상적으로 작동합니다.
따라서, MongoDBBSONPackedArray::toRelaxedExtendedJSON 함수를 사용하여 데이터를 변환할 때, null 값을 처리하는 방법은 위와 같이 옵션을 지정하는 방법을 사용할 수 있습니다.
2025-08-09 04:26