Re: Stripping a JSON of extra characters in PHP
Arno Welzel <[email protected]> Mon, 6 Feb 2023 20:40:47 +0100
| Newsgroups | comp.lang.php |
|---|---|
| Message-ID | <[email protected]> |
The Doctor, 2023-02-06 16:28:
[...]
> The cart is being derived from a previous form being passed into PHP!
[...]
> $arr=array(
> 'store_id' => "store3",
> 'api_token' => "yesguy",
> 'checkout_id' => "chktGLFZQtore3",
> 'txn_total' => $_POST['charge_total'],
> 'environment' => "qa",
> 'action' => "preload",
> 'cart' => array(
> (foreach ($_POST['quantity'] as $key => $value) {
Well - this will result in an array in the JSON named "cart".
> $cart['items'][] =array(
And this will also become an array named "items" inside "cart".
So if you don't want "cart" to be an array in the JSON, then don't
create it this way.
Learn how to read JSON and that the "punctuation" are not just
characters but have a specific meaning. In this case you created an
array and the JSON will have an array as well - indicated by "[" and "]".
--
Arno Welzel
https://arnowelzel.de