라이브러리

[PHP] MongoDBBSONDocument::toRelaxedExtendedJSON - BSON 문서의 Relaxed Extended JSON 표현을 반환합니다.




MongoDBBSONDocument::toRelaxedExtendedJSON


`MongoDBBSONDocument::toRelaxedExtendedJSON`는 MongoDB의 BSON 문서를 편리한 JSON 형식으로 변환하는 메소드입니다. 이 메소드는 `toJSON` 메소드와 유사하지만, `toRelaxedExtendedJSON`은 더 많은 옵션을 제공하고, 더 편리한 JSON 형식을 생성합니다.

사용법


`toRelaxedExtendedJSON` 메소드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

$document = new MongoDBBSONDocument([

    'name' => 'John Doe',

    'age' => 30,

    'address' => [

        'street' => '123 Main St',

        'city' => 'New York',

        'state' => 'NY',

        'zip' => '10001'

    ]

]);



$json = $document->toRelaxedExtendedJSON();



print($json);



결과


#hostingforum.kr
json

{

  "_id" : ObjectId("..."),

  "name" : "John Doe",

  "age" : 30,

  "address" : {

    "street" : "123 Main St",

    "city" : "New York",

    "state" : "NY",

    "zip" : "10001"

  }

}



옵션


`toRelaxedExtendedJSON` 메소드는 다음과 같은 옵션을 제공합니다.

* `indent`: JSON 형식을 들여쓰기 하여 읽기 편하게 만듭니다. 예를 들어, `indent => 2`로 설정하면 JSON 형식이 2칸씩 들여쓰기 됩니다.
* `format`: JSON 형식을 지정합니다. 예를 들어, `format => MongoDBBSONJSON::JSON_PURE`로 설정하면 JSON 형식이 PURE 형식으로 생성됩니다.

예제


#hostingforum.kr
php

$document = new MongoDBBSONDocument([

    'name' => 'John Doe',

    'age' => 30,

    'address' => [

        'street' => '123 Main St',

        'city' => 'New York',

        'state' => 'NY',

        'zip' => '10001'

    ]

]);



$json = $document->toRelaxedExtendedJSON([

    'indent' => 2,

    'format' => MongoDBBSONJSON::JSON_PURE

]);



print($json);



결과


#hostingforum.kr
json

{

  "_id" : ObjectId("..."),

  "name" : "John Doe",

  "age" : 30,

  "address" : {

    "street" : "123 Main St",

    "city" : "New York",

    "state" : "NY",

    "zip" : "10001"

  }

}



참고


* MongoDBBSONDocument::toRelaxedExtendedJSON 메소드는 MongoDB 1.9.0 이상에서 사용할 수 있습니다.
* `toRelaxedExtendedJSON` 메소드는 `toJSON` 메소드와 유사하지만, 더 많은 옵션을 제공합니다.
* `toRelaxedExtendedJSON` 메소드는 편리한 JSON 형식을 생성합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 407 페이지

검색

게시물 검색