Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"In matrimony, to hesitate is sometimes to be saved." -- Butler


devel / comp.lang.php / Re: Stripping a JSON of extra characters in PHP

SubjectAuthor
* Stripping a JSON of extra characters in PHPThe Doctor
+* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
|+* Re: Stripping a JSON of extra characters in PHPArno Welzel
||`* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
|| `* Re: Stripping a JSON of extra characters in PHPArno Welzel
||  `* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
||   `* Re: Stripping a JSON of extra characters in PHPArno Welzel
||    `* Re: Stripping a JSON of extra characters in PHPBen Bacarisse
||     `- Re: Stripping a JSON of extra characters in PHPArno Welzel
|`* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
| +- Re: Stripping a JSON of extra characters in PHPArno Welzel
| `- Re: Stripping a JSON of extra characters in PHPBen Bacarisse
`* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
 `* Re: Stripping a JSON of extra characters in PHPThe Doctor
  `* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
   `* Re: Stripping a JSON of extra characters in PHPThe Doctor
    +* Re: Stripping a JSON of extra characters in PHPJ.O. Aho
    |`- Re: Stripping a JSON of extra characters in PHPThe Doctor
    `* Re: Stripping a JSON of extra characters in PHPArno Welzel
     `* Re: Stripping a JSON of extra characters in PHPThe Doctor
      +* Re: Stripping a JSON of extra characters in PHPThe Doctor
      |`* Re: Stripping a JSON of extra characters in PHPArno Welzel
      | +* Re: Stripping a JSON of extra characters in PHPArno Welzel
      | |`* Re: Stripping a JSON of extra characters in PHPThe Doctor
      | | `* Re: Stripping a JSON of extra characters in PHPArno Welzel
      | |  `- Re: Stripping a JSON of extra characters in PHPThe Doctor
      | `- Re: Stripping a JSON of extra characters in PHPThe Doctor
      `* Re: Stripping a JSON of extra characters in PHPArno Welzel
       `- Re: Stripping a JSON of extra characters in PHPThe Doctor

Pages:12
Re: Stripping a JSON of extra characters in PHP

<trtssh$19ol$38@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=809&group=comp.lang.php#809

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 16:05:37 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trtssh$19ol$38@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <trs7m0$2pkv$29@gallifrey.nk.ca> <trs9fn$ak$1@gallifrey.nk.ca> <k4efniF59f9U2@mid.individual.net>
Injection-Date: Tue, 7 Feb 2023 16:05:37 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="42773"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Tue, 7 Feb 2023 16:05 UTC

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

Re: Stripping a JSON of extra characters in PHP

<trtt6f$19ol$39@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=810&group=comp.lang.php#810

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Tue, 7 Feb 2023 16:10:55 -0000 (UTC)
Organization: NetKnow News
Message-ID: <trtt6f$19ol$39@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <trs9fn$ak$1@gallifrey.nk.ca> <k4efniF59f9U2@mid.individual.net> <k4egigF59f9U3@mid.individual.net>
Injection-Date: Tue, 7 Feb 2023 16:10:55 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="42773"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Tue, 7 Feb 2023 16:10 UTC

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

Re: Stripping a JSON of extra characters in PHP

<k4kvg1F6414U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=813&group=comp.lang.php#813

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@arnowelzel.de (Arno Welzel)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Thu, 9 Feb 2023 20:22:42 +0100
Lines: 79
Message-ID: <k4kvg1F6414U1@mid.individual.net>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <trs9fn$ak$1@gallifrey.nk.ca>
<k4efniF59f9U2@mid.individual.net> <k4egigF59f9U3@mid.individual.net>
<trtt6f$19ol$39@gallifrey.nk.ca>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 9sF4Z4zKFWvdd/tuVRQZdwtqi/pA9pyB2RyWoUfMKuD+lPlnqS
Cancel-Lock: sha1:D07pVOiyoYZLCYo/sj1AVowETUs=
Content-Language: de-DE
In-Reply-To: <trtt6f$19ol$39@gallifrey.nk.ca>
 by: Arno Welzel - Thu, 9 Feb 2023 19:22 UTC

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

Re: Stripping a JSON of extra characters in PHP

<ts3mul$17ev$25@gallifrey.nk.ca>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=814&group=comp.lang.php#814

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.nk.ca!.POSTED.doctor.nl2k.ab.ca!not-for-mail
From: doctor@doctor.nl2k.ab.ca (The Doctor)
Newsgroups: comp.lang.php
Subject: Re: Stripping a JSON of extra characters in PHP
Date: Thu, 9 Feb 2023 21:01:09 -0000 (UTC)
Organization: NetKnow News
Message-ID: <ts3mul$17ev$25@gallifrey.nk.ca>
References: <tre1ei$2lti$75@gallifrey.nk.ca> <k4egigF59f9U3@mid.individual.net> <trtt6f$19ol$39@gallifrey.nk.ca> <k4kvg1F6414U1@mid.individual.net>
Injection-Date: Thu, 9 Feb 2023 21:01:09 -0000 (UTC)
Injection-Info: gallifrey.nk.ca; posting-host="doctor.nl2k.ab.ca:204.209.81.1";
logging-data="40415"; mail-complaints-to="usenet@gallifrey.nk.ca"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: doctor@doctor.nl2k.ab.ca (The Doctor)
 by: The Doctor - Thu, 9 Feb 2023 21:01 UTC

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

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor