Re: Stripping a JSON of extra characters in PHP
[email protected] (The Doctor) Thu, 9 Feb 2023 21:01:09 -0000 (UTC)
| Newsgroups | comp.lang.php |
|---|---|
| Organization | NetKnow News |
| Message-ID | <[email protected]> |
In article <[email protected]>, Arno Welzel <[email protected]> wrote: >The Doctor, 2023-02-07 17:10: > >> In article <[email protected]>, >> Arno Welzel <[email protected]> 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 [email protected] Ici [email protected] 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