json_decode
文字列をオブジェクトにデコードするために使用します。
このコード:
$str = "{\"nonce\":4658477652655443541,\"orders\":[{\"notificationId\":\"android.test.purchased\",\"orderId\":\"transactionId.android.test.purchased\",\"packageName\":\"com.coolboy.coolapp\",\"productId\":\"android.test.purchased\",\"purchaseTime\":1350913071409,\"purchaseState\":0}]}";
$json = json_decode($str);
var_dump($json);
プロデュース:
class stdClass#1 (2) {
public $nonce =>
double(4.6584776526554E+18)
public $orders =>
array(1) {
[0] =>
class stdClass#2 (6) {
public $notificationId =>
string(22) "android.test.purchased"
public $orderId =>
string(36) "transactionId.android.test.purchased"
public $packageName =>
string(19) "com.coolboy.coolapp"
public $productId =>
string(22) "android.test.purchased"
public $purchaseTime =>
double(1350913071409)
public $purchaseState =>
int(0)
}
}
}
そしてもちろん、次のことができます。
$nonce = $json->nonce;
$notificationId = $json->orders[0]->notificationId;
// etc...
JSON の詳細: