Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #19286 > unrolled thread

Stripping a JSON of extra characters in PHP

Started bydoctor@doctor.nl2k.ab.ca (The Doctor)
First post2023-02-01 15:45 +0000
Last post2023-02-07 16:05 +0000
Articles 11 on this page of 31 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-01 15:45 +0000
    Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-01 16:09 +0000
      Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-03 18:12 +0100
        Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-03 23:56 +0000
          Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 00:28 +0100
            Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-05 00:06 +0000
              Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 14:17 +0100
                Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-05 20:58 +0000
                  Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 23:38 +0100
      Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-04 11:23 +0100
        Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 00:30 +0100
        Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-04 23:44 +0000
    Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-05 16:14 +0100
      Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-06 01:31 +0000
        Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-06 08:14 +0100
          Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-06 15:28 +0000
            Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-06 18:14 +0100
              Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 00:56 +0000
            Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-06 20:40 +0100
              Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 00:57 +0000
                Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 01:28 +0000
                  Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-07 09:16 +0100
                    Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-07 09:31 +0100
                      Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 16:10 +0000
                        Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-09 20:22 +0100
                          Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-09 21:01 +0000
                            Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-10 11:49 +0100
                              Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-10 14:39 +0000
                    Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 16:05 +0000
                Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-07 09:13 +0100
                  Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 16:05 +0000

Page 2 of 2 — ← Prev page 1 [2]


#19307

Fromdoctor@doctor.nl2k.ab.ca (The Doctor)
Date2023-02-07 01:28 +0000
Message-ID<trs9fn$ak$1@gallifrey.nk.ca>
In reply to#19306
In article <trs7m0$2pkv$29@gallifrey.nk.ca>,
The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
>In article <k4d3dvFtd5nU1@mid.individual.net>,
>Arno Welzel  <usenet@arnowelzel.de> wrote:
>>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 "]".
>>
>
>Again basing this on Moneris prereqs.
>

cart is subarray with the main array,  added items in the cart
is a subarray of the cart.

Source 

https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

>>-- 
>>Arno Welzel
>>https://arnowelzel.de
>>
>
>
>-- 
>Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
>Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
>Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
>Extremism is for those who love judging, and care nothing for accuracy.
>-unknown Beware https://mindspring.com


-- 
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

[toc] | [prev] | [next] | [standalone]


#19309

FromArno Welzel <usenet@arnowelzel.de>
Date2023-02-07 09:16 +0100
Message-ID<k4efniF59f9U2@mid.individual.net>
In reply to#19307
The Doctor, 2023-02-07 02:28:

[...]
> cart is subarray with the main array,  added items in the cart
> is a subarray of the cart.>
> Source 
> 
> https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

No! Cart is an OBJECT there:

"cart":{
...
}

Also contact details:

"contact_details":{
...
}

The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.

As I said: learn how to read JSON and try to understand how that format
works!

Also see: <https://www.json.org/json-en.html>


-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#19310

FromArno Welzel <usenet@arnowelzel.de>
Date2023-02-07 09:31 +0100
Message-ID<k4egigF59f9U3@mid.individual.net>
In reply to#19309
Arno Welzel, 2023-02-07 09:16:

> The Doctor, 2023-02-07 02:28:
> 
> [...]
>> cart is subarray with the main array,  added items in the cart
>> is a subarray of the cart.>
>> Source 
>>
>> https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
> 
> No! Cart is an OBJECT there:
> 
> "cart":{
> ...
> }
> 
> Also contact details:
> 
> "contact_details":{
> ...
> }
> 
> The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.
> 
> As I said: learn how to read JSON and try to understand how that format
> works!
> 
> Also see: <https://www.json.org/json-en.html>

In addition:

To create an OBJECT in PHP use something like this - as a reduced example:

<?php
class CartItem
{
  public $url;
  public $description;
  public $product_code;
  public $unit_cost;
  public $quantity;
}

class TaxItem
{
  public $amount;
  public $description;
  public $rate;
}

class Cart
{
  public $items;
  public $subtotal;
  public $tax;
};

$cart = new Cart();

$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item1.jpg";
$cartItem->description = "One item";
$cartItem->product_code = "one_item";
$cartItem->unit_cost = "100.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;

$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item2.jpg";
$cartItem->description = "Two item";
$cartItem->product_code = "two_item";
$cartItem->unit_cost = "200.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;

$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item3.jpg";
$cartItem->description = "Three item";
$cartItem->product_code = "three_item";
$cartItem->unit_cost = "100.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;

$cart->subtotal = "400.00";

$taxItem = new TaxItem();
$taxItem->amount = "52.00";
$taxItem->description = "Taxes";
$taxItem->rate = "13.00";
$cart->tax = $taxItem;

echo json_encode($cart, JSON_PRETTY_PRINT);
?>

Result of this as formatted output:

{
    "items": [
        {
            "url": "https:\\\/\\\/example.com\\\/examples\\\/item1.jpg",
            "description": "One item",
            "product_code": "one_item",
            "unit_cost": "100.00",
            "quantity": "1"
        },
        {
            "url": "https:\\\/\\\/example.com\\\/examples\\\/item2.jpg",
            "description": "Two item",
            "product_code": "two_item",
            "unit_cost": "200.00",
            "quantity": "1"
        },
        {
            "url": "https:\\\/\\\/example.com\\\/examples\\\/item3.jpg",
            "description": "Three item",
            "product_code": "three_item",
            "unit_cost": "100.00",
            "quantity": "1"
        }
    ],
    "subtotal": "400.00",
    "tax": {
        "amount": "52.00",
        "description": "Taxes",
        "rate": "13.00"
    }
}

Hopefully you understand the idea now - if you don't want an ARRAY in
the JSON then do not create one! If the specification asks for an OBJECT
then use an OBJECT based on a class with named members.

-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#19314

Fromdoctor@doctor.nl2k.ab.ca (The Doctor)
Date2023-02-07 16:10 +0000
Message-ID<trtt6f$19ol$39@gallifrey.nk.ca>
In reply to#19310
In article <k4egigF59f9U3@mid.individual.net>,
Arno Welzel  <usenet@arnowelzel.de> wrote:
>Arno Welzel, 2023-02-07 09:16:
>
>> The Doctor, 2023-02-07 02:28:
>> 
>> [...]
>>> cart is subarray with the main array,  added items in the cart
>>> is a subarray of the cart.>
>>> Source 
>>>
>>> https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
>> 
>> No! Cart is an OBJECT there:
>> 
>> "cart":{
>> ...
>> }
>> 
>> Also contact details:
>> 
>> "contact_details":{
>> ...
>> }
>> 
>> The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.
>> 
>> As I said: learn how to read JSON and try to understand how that format
>> works!
>> 
>> Also see: <https://www.json.org/json-en.html>
>
>In addition:
>
>To create an OBJECT in PHP use something like this - as a reduced example:
>
><?php
>class CartItem
>{
>  public $url;
>  public $description;
>  public $product_code;
>  public $unit_cost;
>  public $quantity;
>}
>
>class TaxItem
>{
>  public $amount;
>  public $description;
>  public $rate;
>}
>
>class Cart
>{
>  public $items;
>  public $subtotal;
>  public $tax;
>};
>
>$cart = new Cart();
>
>$cartItem = new CartItem();
>$cartItem->url = "https:\/\/example.com\/examples\/item1.jpg";
>$cartItem->description = "One item";
>$cartItem->product_code = "one_item";
>$cartItem->unit_cost = "100.00";
>$cartItem->quantity = "1";
>$cart->items[] = $cartItem;
>
>$cartItem = new CartItem();
>$cartItem->url = "https:\/\/example.com\/examples\/item2.jpg";
>$cartItem->description = "Two item";
>$cartItem->product_code = "two_item";
>$cartItem->unit_cost = "200.00";
>$cartItem->quantity = "1";
>$cart->items[] = $cartItem;
>
>$cartItem = new CartItem();
>$cartItem->url = "https:\/\/example.com\/examples\/item3.jpg";
>$cartItem->description = "Three item";
>$cartItem->product_code = "three_item";
>$cartItem->unit_cost = "100.00";
>$cartItem->quantity = "1";
>$cart->items[] = $cartItem;
>
>$cart->subtotal = "400.00";
>
>$taxItem = new TaxItem();
>$taxItem->amount = "52.00";
>$taxItem->description = "Taxes";
>$taxItem->rate = "13.00";
>$cart->tax = $taxItem;
>
>echo json_encode($cart, JSON_PRETTY_PRINT);
>?>
>
>Result of this as formatted output:
>
>{
>    "items": [
>        {
>            "url": "https:\\\/\\\/example.com\\\/examples\\\/item1.jpg",
>            "description": "One item",
>            "product_code": "one_item",
>            "unit_cost": "100.00",
>            "quantity": "1"
>        },
>        {
>            "url": "https:\\\/\\\/example.com\\\/examples\\\/item2.jpg",
>            "description": "Two item",
>            "product_code": "two_item",
>            "unit_cost": "200.00",
>            "quantity": "1"
>        },
>        {
>            "url": "https:\\\/\\\/example.com\\\/examples\\\/item3.jpg",
>            "description": "Three item",
>            "product_code": "three_item",
>            "unit_cost": "100.00",
>            "quantity": "1"
>        }
>    ],
>    "subtotal": "400.00",
>    "tax": {
>        "amount": "52.00",
>        "description": "Taxes",
>        "rate": "13.00"
>    }
>}
>
>Hopefully you understand the idea now - if you don't want an ARRAY in
>the JSON then do not create one! If the specification asks for an OBJECT
>then use an OBJECT based on a class with named members.
>

But The information is being pulled from a pre-filled hence you need,
Something like

//$items=array(
if (isset($_POST["submit"])){

foreach ($_POST['quantity'] as $key => $value) {
  if( $value > 0){
      if(isset($_POST['with_gst'][$key])){
	    $unit_cost = 63.00;
	}else{
      $unit_cost = 60.00; //no gst included
  }
$newsubtotal = ($unit_cost * $value);
$quantity = ($value);
$itemssubarray[]= array(
'url' => "https://www.pdsolutions.ca/images/newwhiteheader.png",
'description' => $_POST['description'][$key],
'product_code' => $_POST['id'][$key],
'unit_cost' => $unit_cost,
'quantity' => $quantity,
);
	   
}  
$subtotal = $subtotal+ $newsubtotal;
$items_count++;
}
array_push($items, $itemssubarray);

}
//);
					      
  $cartarray[] = array(
  "cart"=>array( $items
  ),
 'subtotal' => $subtotal,
  "tax"=>array(
  'amount' => ($subtotal * 0.05),
  'description' => "GST",
'rate' => "5.00",
),
);


>-- 
>Arno Welzel
>https://arnowelzel.de
>


-- 
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

[toc] | [prev] | [next] | [standalone]


#19317

FromArno Welzel <usenet@arnowelzel.de>
Date2023-02-09 20:22 +0100
Message-ID<k4kvg1F6414U1@mid.individual.net>
In reply to#19314
The Doctor, 2023-02-07 17:10:

> In article <k4egigF59f9U3@mid.individual.net>,
> Arno Welzel  <usenet@arnowelzel.de> wrote:

[...]

>> Hopefully you understand the idea now - if you don't want an ARRAY in
>> the JSON then do not create one! If the specification asks for an OBJECT
>> then use an OBJECT based on a class with named members.
>>
> 
> But The information is being pulled from a pre-filled hence you need,
> Something like

So what? You can also create objects based on "pre-filled" data.

> //$items=array(
> if (isset($_POST["submit"])){
> 
> foreach ($_POST['quantity'] as $key => $value) {
>   if( $value > 0){
>       if(isset($_POST['with_gst'][$key])){
> 	    $unit_cost = 63.00;
> 	}else{
>       $unit_cost = 60.00; //no gst included
>   }
> $newsubtotal = ($unit_cost * $value);
> $quantity = ($value);

> $itemssubarray[]= array(

CREATE AN OBJECT HERE!

First define a class for this above all the code:

class CartItem
{
  public $url;
  public $description;
  public $product_code;
  public $unit_cost;
  public $quantity;
}

And then use THIS(!) to create the OBJECT(!) for it:

$item = new Item();
$item->url = "https://www.pdsolutions.ca/images/newwhiteheader.png";
$item->description = $_POST['description'][$key];
$item->product_code = $_POST['id'][$key];
$item->unit_cost = $unit_cost;
$item->quantity = $quantity;
$itemssubarray[] = $item;

[...]
>   $cartarray[] = array(
>   "cart"=>array( $items
>   ),

NO! Create an OBJECT!

>  'subtotal' => $subtotal,
>   "tax"=>array(
>   'amount' => ($subtotal * 0.05),
>   'description' => "GST",
> 'rate' => "5.00",
> ),
> );


Sorry - but if you are really not able to understand what I write, you
should pay someone to do the job for you.


-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#19318

Fromdoctor@doctor.nl2k.ab.ca (The Doctor)
Date2023-02-09 21:01 +0000
Message-ID<ts3mul$17ev$25@gallifrey.nk.ca>
In reply to#19317
In article <k4kvg1F6414U1@mid.individual.net>,
Arno Welzel  <usenet@arnowelzel.de> wrote:
>The Doctor, 2023-02-07 17:10:
>
>> In article <k4egigF59f9U3@mid.individual.net>,
>> Arno Welzel  <usenet@arnowelzel.de> wrote:
>
>[...]
>
>>> Hopefully you understand the idea now - if you don't want an ARRAY in
>>> the JSON then do not create one! If the specification asks for an OBJECT
>>> then use an OBJECT based on a class with named members.
>>>
>> 
>> But The information is being pulled from a pre-filled hence you need,
>> Something like
>
>So what? You can also create objects based on "pre-filled" data.
>
>> //$items=array(
>> if (isset($_POST["submit"])){
>> 
>> foreach ($_POST['quantity'] as $key => $value) {
>>   if( $value > 0){
>>       if(isset($_POST['with_gst'][$key])){
>> 	    $unit_cost = 63.00;
>> 	}else{
>>       $unit_cost = 60.00; //no gst included
>>   }
>> $newsubtotal = ($unit_cost * $value);
>> $quantity = ($value);
>
>> $itemssubarray[]= array(
>
>CREATE AN OBJECT HERE!
>
>First define a class for this above all the code:
>
>class CartItem
>{
>  public $url;
>  public $description;
>  public $product_code;
>  public $unit_cost;
>  public $quantity;
>}
>
>And then use THIS(!) to create the OBJECT(!) for it:
>
>$item = new Item();
>$item->url = "https://www.pdsolutions.ca/images/newwhiteheader.png";
>$item->description = $_POST['description'][$key];
>$item->product_code = $_POST['id'][$key];
>$item->unit_cost = $unit_cost;
>$item->quantity = $quantity;
>$itemssubarray[] = $item;
>
>[...]
>>   $cartarray[] = array(
>>   "cart"=>array( $items
>>   ),
>
>NO! Create an OBJECT!
>
>>  'subtotal' => $subtotal,
>>   "tax"=>array(
>>   'amount' => ($subtotal * 0.05),
>>   'description' => "GST",
>> 'rate' => "5.00",
>> ),
>> );
>
>
>Sorry - but if you are really not able to understand what I write, you
>should pay someone to do the job for you.


The problem is the way the supplier wants to oush the information.

>
>-- 
>Arno Welzel
>https://arnowelzel.de
>


-- 
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
Sometimes what's billed as light is the darkness. -unknown Beware https://mindspring.com

[toc] | [prev] | [next] | [standalone]


#19319

From"J.O. Aho" <user@example.net>
Date2023-02-10 11:49 +0100
Message-ID<k4mlqlFdtacU1@mid.individual.net>
In reply to#19318
On 2/9/23 22:01, The Doctor wrote:
> In article <k4kvg1F6414U1@mid.individual.net>,
> Arno Welzel  <usenet@arnowelzel.de> wrote:

>> Sorry - but if you are really not able to understand what I write, you
>> should pay someone to do the job for you.
> 
> The problem is the way the supplier wants to oush the information.

You need to follow the api requierment which says that the json should 
have an array of json objects, not an array of arrya with array.

Your task is to take the posted value convert it to be in the format 
that the api requiers.

Using classes will make the code more readable and you can break things 
up into smaller chunks when you are writing your code. I think it's 
beter to transform things into a variable and then assing it to the 
object's variable to make the assignment clear and simple. Don't forget 
that the classes can include arrays, but only use those in the places 
where you need it, IMHO it can be sometimes good to iniate the array in 
the class constructor (this only can be done as long as the api don't 
require the array to be omitted if no values).

Don't forget that the company providing the API also has a support team 
which can help, sure  it may come with a cost, depending on the deggree 
of help and how much they think is out of topic. For them it's importnat 
to earn money and if they think helpiing you will give them enough money 
in return, they may help more than they normal support is mandated to do.

-- 
  //Aho

[toc] | [prev] | [next] | [standalone]


#19320

Fromdoctor@doctor.nl2k.ab.ca (The Doctor)
Date2023-02-10 14:39 +0000
Message-ID<ts5kv2$1fqt$81@gallifrey.nk.ca>
In reply to#19319
In article <k4mlqlFdtacU1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
>On 2/9/23 22:01, The Doctor wrote:
>> In article <k4kvg1F6414U1@mid.individual.net>,
>> Arno Welzel  <usenet@arnowelzel.de> wrote:
>
>>> Sorry - but if you are really not able to understand what I write, you
>>> should pay someone to do the job for you.
>> 
>> The problem is the way the supplier wants to oush the information.
>
>You need to follow the api requierment which says that the json should 
>have an array of json objects, not an array of arrya with array.
>
>Your task is to take the posted value convert it to be in the format 
>that the api requiers.
>
>Using classes will make the code more readable and you can break things 
>up into smaller chunks when you are writing your code. I think it's 
>beter to transform things into a variable and then assing it to the 
>object's variable to make the assignment clear and simple. Don't forget 
>that the classes can include arrays, but only use those in the places 
>where you need it, IMHO it can be sometimes good to iniate the array in 
>the class constructor (this only can be done as long as the api don't 
>require the array to be omitted if no values).
>
>Don't forget that the company providing the API also has a support team 
>which can help, sure  it may come with a cost, depending on the deggree 
>of help and how much they think is out of topic. For them it's importnat 
>to earn money and if they think helpiing you will give them enough money 
>in return, they may help more than they normal support is mandated to do.
>

There is no support from the providing company.

>-- 
>  //Aho
>


-- 
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
We have been misled: there is only one Jesus. -unknown Beware https://mindspring.com

[toc] | [prev] | [next] | [standalone]


#19313

Fromdoctor@doctor.nl2k.ab.ca (The Doctor)
Date2023-02-07 16:05 +0000
Message-ID<trtssh$19ol$38@gallifrey.nk.ca>
In reply to#19309
In article <k4efniF59f9U2@mid.individual.net>,
Arno Welzel  <usenet@arnowelzel.de> wrote:
>The Doctor, 2023-02-07 02:28:
>
>[...]
>> cart is subarray with the main array,  added items in the cart
>> is a subarray of the cart.>
>> Source 
>> 
>> https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
>
>No! Cart is an OBJECT there:
>
>"cart":{
>...
>}
>
>Also contact details:
>
>"contact_details":{
>...
>}
>
>The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.
>
>As I said: learn how to read JSON and try to understand how that format
>works!
>
>Also see: <https://www.json.org/json-en.html>
>


Got you!

>
>-- 
>Arno Welzel
>https://arnowelzel.de
>


-- 
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

[toc] | [prev] | [next] | [standalone]


#19308

FromArno Welzel <usenet@arnowelzel.de>
Date2023-02-07 09:13 +0100
Message-ID<k4efhpF59f9U1@mid.individual.net>
In reply to#19306
The Doctor, 2023-02-07 01:57:

> In article <k4d3dvFtd5nU1@mid.individual.net>,
> Arno Welzel  <usenet@arnowelzel.de> wrote:
>> 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 "]".
>>
> 
> Again basing this on Moneris prereqs.

What is "Moneris prereqs"?

Your OP was: "How can I carefully strip unnecessary punctuation?" I
tried to explain to you, where these "punctuation" comes from. But if
you don't accept the facts, then you have to live with it.


-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#19312

Fromdoctor@doctor.nl2k.ab.ca (The Doctor)
Date2023-02-07 16:05 +0000
Message-ID<trtsrr$19ol$37@gallifrey.nk.ca>
In reply to#19308
In article <k4efhpF59f9U1@mid.individual.net>,
Arno Welzel  <usenet@arnowelzel.de> wrote:
>The Doctor, 2023-02-07 01:57:
>
>> In article <k4d3dvFtd5nU1@mid.individual.net>,
>> Arno Welzel  <usenet@arnowelzel.de> wrote:
>>> 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 "]".
>>>
>> 
>> Again basing this on Moneris prereqs.
>
>What is "Moneris prereqs"?
>
>Your OP was: "How can I carefully strip unnecessary punctuation?" I
>tried to explain to you, where these "punctuation" comes from. But if
>you don't accept the facts, then you have to live with it.
>
>

https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

>-- 
>Arno Welzel
>https://arnowelzel.de
>


-- 
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b 
Extremism is for those who love judging, and care nothing for accuracy. -unknown Beware https://mindspring.com

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.php


csiph-web