2

所以我有使用 PHP 服务器验证的应用内计费。但是,我不知道如何在 PHP 中将我的签名数据字符串分成单独的字符串。当我在 PHP 中回显 $signedData 时,我得到以下信息。

{\"nonce\":4658477652655443541,\"orders\":[{\"notificationId\":\"android.test.purchased\",\"orderId\":\"transactionId.android.test.purchased\",\"packageName\":\"com.coolboy.coolapp\",\"productId\":\"android.test.purchased\",\"purchaseTime\":1350913071409,\"purchaseState\":0}]}

你如何将 PHP 中的 nonce、orders 等分隔为单独的变量?

谢谢

4

2 回答 2

3

用于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 的更多信息:

于 2012-10-22T16:21:29.390 回答
2

那是JSON。

$array = json_decode($var);
于 2012-10-22T16:21:34.717 回答