Convert nested json object to php string without separator values

I get an HTTP message with the following JSON object:

{"notification":{"version":6.0,"attemptCount":0,"role":"VENDOR","site":"nicholeen","receipt":"********","currency":"USD","transactionType":"TEST","transactionTime":1406070122781,"paymentMethod":"VISA","totalProductAmount":1.00,"totalTaxAmount":0.00,"totalShippingAmount":0.00,"customer":{"shipping":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":{}},"billing":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":{}}},"lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"customerProductAmount":1.00,"customerTaxAmount":0.00}]},"verification":"2745A502"}

I need to convert the notification JSON object to the JSON string assigned to the PHP variable, without losing any data, including decimal numbers.

I am currently getting IPN using $ipn_raw = file_get_contents('php://input');. Then I json_decode JSON into a PHP variable and then re-encode the notification part with json_encode. Here is the code:

$ipn_raw = file_get_contents('php://input');
$ipn = json_decode($ipn_raw);
$notification = $ipn['notification'];
$result = json_encode($notification);

However, the result breaks up some values ​​giving me the following:

{"version":6,"attemptCount":0,"role":"VENDOR","site":"nicholeen","receipt":"********","currency":"USD","transactionType":"TEST","transactionTime":1406095846441,"paymentMethod":"VISA","totalProductAmount":1,"totalTaxAmount":0,"totalShippingAmount":0,"customer":{"shipping":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":[]},"billing":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":[]}},"lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"customerProductAmount":1,"customerTaxAmount":0}]}

You can see that version 6.0 is now only version 6, totalProductAmount was 1.00 and now 1, etc.

How can I do this without changing the values ​​as a result?

Thank!

, , . Clickbank , SHA 1, IP- 6 (. https://support.clickbank.com/entries/22803622-Instant-Notification-Service)

1) JSON/DSL JSON "" IPN. 2) JSON "" JSON. { }, JSON. 3) . . 4) SHA 1 -, 3. 5) 8 , 4. "" IP- v6.

, , , - .

+4
3

(, JSON), JSON (, regex):

$result = preg_replace(array('^\{[^{]', '[^}]\}$'), '', $in);

, , . ( , , , JSON , .. , , , } ( ))


, : https://bugs.php.net/bug.php?id=50224, , 6.0 JavaScript . . : PHP- json_decode int

+2

: 6.0 6 . , PHP . , json_decode() , .

, json quites, PHP . :

$jsonRaw = '{"notification":{"version":6.0,"attemptCount":0,"role":"VENDOR","site":"nicholeen","receipt":"********","currency":"USD","transactionType":"TEST","transactionTime":1406070122781,"paymentMethod":"VISA","totalProductAmount":1.00,"totalTaxAmount":0.00,"totalShippingAmount":0.00,"customer":{"shipping":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":{}},"billing":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":{}}},"lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"customerProductAmount":1.00,"customerTaxAmount":0.00}]},"verification":"2745A502"}';

$jsonRaw = preg_replace('/(\b)([0-9]+\.[0-9]+)(\b)/', '$1"$2"$3', $jsonRaw);
$jsonObj = json_decode($jsonRaw);

, , . , :

$notification = $jsonObj->notification;
$result       = json_encode($notification);
$result       = preg_replace('/"([0-9]+\.[0-9]+)"/', '$1', $result);

: , float. , json "6.00", , float. , , - , ( , Json-)

+1

For those who are interested, here is what I ended up using:

$json_ipn = preg_replace('({"notification":|,"verification"([\s\S]*))', '', $ipn_raw);
0
source

All Articles