MongoDB\BSON\PackedArray::fromJSON
(mongodb >=1.20.0)
MongoDB\BSON\PackedArray::fromJSON — Construct a new BSON array instance from a JSON string
説明
Converts an » extended JSON string to its BSON representation.
パラメータ
json
(string)-
JSON value to be converted.
戻り値
Returns a new MongoDB\BSON\PackedArray instance.
エラー / 例外
- Throws MongoDB\Driver\Exception\InvalidArgumentException on argument parsing errors.
- Throws MongoDB\Driver\Exception\UnexpectedValueException if the JSON value cannot be converted to a BSON array (e.g. due to a syntax error).
例
例1 MongoDB\BSON\PackedArray::fromJSON() example
<?php
$json = '[ "foo", { "$numberInt" : "123" }, { "$numberLong" : "4294967295" }, { "$oid" : "56315a7c6118fd1b920270b1" } ]';
$packedArray = MongoDB\BSON\PackedArray::fromJSON($json);
var_dump($packedArray);
?>
上の例の出力は以下となります。
object(MongoDB\BSON\PackedArray)#1 (2) { ["data"]=> string(68) "MQAAAAIwAAQAAABmb28AEDEAewAAABIyAP////8AAAAABzMAVjFafGEY/RuSAnCxAA==" ["value"]=> array(4) { [0]=> string(3) "foo" [1]=> int(123) [2]=> int(4294967295) [3]=> object(MongoDB\BSON\ObjectId)#2 (1) { ["oid"]=> string(24) "56315a7c6118fd1b920270b1" } } }
参考
- MongoDB\BSON\PackedArray::fromPHP() - Construct a new BSON array instance from PHP data
- » MongoDB Extended JSON
- » BSON Types
+add a note
User Contributed Notes
There are no user contributed notes for this page.
↑ and ↓ to navigate •
Enter to select •
Esc to close
Press Enter without
selection to search using Google